Click here to Skip to main content
15,880,956 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a vbscript as follows :

set nice = wscript.createobject ("wscript.shell")

on error resume next

nice.run "cmd.exe"

wscript.sleep 400

nice.sendkeys "cd C:\Users\Annamaria.Mikecz01\Desktop\CENT-ERIKA-GUI"
nice.sendkeys "{enter}"

nice.sendkeys "capture.jpg"
nice.sendkeys "{enter}"
wscript.sleep 300
nice.sendkeys "%{f4}"


Now I want the username to be picked dynamically for whoever is logged in the system. So with what code should i replace this one : "C:\Users\Annamaria.Mikecz01\Desktop".


Please help

What I have tried:

set nice = wscript.createobject ("wscript.shell")

on error resume next

nice.run "cmd.exe"

wscript.sleep 400

nice.sendkeys "cd C:\Users\Annamaria.Mikecz01\Desktop\CENT-ERIKA-GUI"
nice.sendkeys "{enter}"

nice.sendkeys "capture.jpg"
nice.sendkeys "{enter}"
wscript.sleep 300
nice.sendkeys "%{f4}"
Posted
Updated 10-Jan-18 6:29am

1 solution

Special folders - VBScript - SS64.com[^]

So:
Dim folderPath
folderPath = nice.SpecialFolders("Desktop")
folderPath = folderPath & "\CENT-ERIKA-GUI"

nice.SendKeys "cd "
nice.SendKeys folderPath
nice.SendKeys "{enter}"


However, it's not a good idea to rely on SendKeys. If you're just trying to open a file in its associated application, use the Run method instead.
Dim nice
Dim filePath

Set nice = Wscript.CreateObject("wscript.shell")
filePath = nice.SpecialFolders("Desktop")
filePath = filePath & "\CENT-ERIKA-GUI\capture.jpg"

nice.Run filePath
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900