chadmanvb
asked on
launch a vbs script as admin with visua basic .net
I have a .net application that i would like to use to launch some vbs scripts as an admin. Normally I launch a command window within Windows 7 as administrator and can run the vbs scripts. I have tried to use the below code, but it's not working. Any ideas?
Dim starthttpWatch As New System.Diagnostics.Process
starthttpWatch.StartInfo.W orkingDire ctory = "c:\"
starthttpWatch.StartInfo.R edirectSta ndardOutpu t = True
starthttpWatch.StartInfo.F ileName = "cmd.exe"
starthttpWatch.StartInfo.A rguments = "\c C:\Temp\WorkstationMonitor \Enable-ht tpwatch-v2 .0.vbs"
starthttpWatch.StartInfo.U seShellExe cute = False
starthttpWatch.StartInfo.C reateNoWin dow = True
starthttpWatch.StartInfo.U serName = strPPAccount
starthttpWatch.StartInfo.P assword = pwd
starthttpWatch.Start()
starthttpWatch.WaitForExit ()
starthttpWatch.Dispose()
Dim starthttpWatch As New System.Diagnostics.Process
starthttpWatch.StartInfo.W
starthttpWatch.StartInfo.R
starthttpWatch.StartInfo.F
starthttpWatch.StartInfo.A
starthttpWatch.StartInfo.U
starthttpWatch.StartInfo.C
starthttpWatch.StartInfo.U
starthttpWatch.StartInfo.P
starthttpWatch.Start()
starthttpWatch.WaitForExit
starthttpWatch.Dispose()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks! That did work after I set usershellexecute to false. I was trying another appoach, but still not sure what way I want to use. I was looking at just starting my app as a admin by changing the
<requestedExecutionLevel level="requireAdministrato r" uiAccess="false" />
in the app.manifest. This also seems to work well and forces users to enter the user/password the first time they launch the application.
<requestedExecutionLevel level="requireAdministrato
in the app.manifest. This also seems to work well and forces users to enter the user/password the first time they launch the application.
ASKER
Dim procInfo As New ProcessStartInfo()
procInfo.UseShellExecute = True
procInfo.FileName = "CMD.exe"
procInfo.Arguments = "/c C:\Temp\WorkstationMonitor
procInfo.WorkingDirectory = Application.StartupPath
procInfo.Verb = "runas"
Process.Start(procInfo)