0
I am a moderately educated novice computer enthusiast and am remotely mildly educated in vbscript and I need help. Here is the order of events...
I used Winaero Tweaker on my PC (running Windows 10 Home) to create an elevated shortcut to a virtual CD running an unlock program for my WD Passport Drive.
Normally, I click a shortcut to the program on the drive, say "yes" to UAC, then click the resulting end window telling me the drive is unlocked. The Winaero elevated shortcut works beautifully except it leaves the end window open.
Here is the target:
C:\WINDOWS\system32\cmd.exe /c start "" schtasks.exe /run /tn "WD Drive Unlock.exe_-943894699"
So, I thought I might try a VB script calling the shortcut, then simply entering {esc} or ~ to close the window. Simple. NOT. I cannot get the window to close, God Save the Queen.
My attempt using the elevated shortcut (H-IT.lnk
):
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\USERS\OWNER\DESKTOP\H-IT.lnk" & Chr(34), 0
WScript.Sleep 1500
WshShell.AppActivate "wd drive"
WshShell.SendKeys "{esc}"
Set WshShell = Nothing
This executes the shortcut just like the shortcut executes the shortcut, but the resulting program window entitled "WD Drive Unlocked" remains OPEN (just like the shortcut).
So, I thought, why not utilize the shortcut's target and circumvent the shortcut all together....for me a midnight nightmare. Here's my embarrassing attempt (intro to VB was 20 yrs ago):
And my attempt to circumvent the shortcut:
Set WshShell = WScript.CreateObject("WScript.Shell")
Command = "%WINDIR%\cmd.exe /c start ""schtasks.exe /run /tn ""WD Drive Unlock.exe_-943894699""
WshShell.Run command
WScript.Sleep 1500
WshShell.AppActivate "wd drive"
WshShell.SendKeys "{esc}"
Set WshShell = Nothing:
I care not about the programming; I just want to unlock my drive in one click with no UAC and no dialog remnants.
Why is the shortcut's target
cmd.exe
instead ofschtasks.exe
? – I say Reinstate Monica – 2017-05-04T22:32:44.910Twisty: I don't know if your question was open or for me directly. All i can add is that short answer is "because that's the way Winaero Tweaker generated it". I lack the education to tease out why. Maybe calling schtasks.exe directly in the script doesn't work at all or doesn't work as cleanly as using cmd.exe . Great question. Maybe someone in the forum can answer it. – John D Brown MD MPH – 2017-05-05T10:22:58.760
The question was directed at you and your answer makes sense. Try making the shortcut point to
schtasks.exe /run /tn "WD Drive Unlock.exe_-943894699"
and see if that makes the window close properly. – I say Reinstate Monica – 2017-05-05T11:42:26.510Alas, no. However, the shortcut is much more efficient and just as effective. It seems calling the command processor is somehow an automated programming process when creating all elevated shortcuts in the Winaero Tweak program. I suspect it somehow has a utility for some shortcuts and is but a harmless redundancy for others like mine. I left it out. Thanks, Twisty. – John D Brown MD MPH – 2017-05-07T23:28:11.283