Solved

launch a vbs script as admin with visua basic .net

Posted on 2014-04-14
3
360 Views
Last Modified: 2014-04-17
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.WorkingDirectory = "c:\"
            starthttpWatch.StartInfo.RedirectStandardOutput = True
            starthttpWatch.StartInfo.FileName = "cmd.exe"
            starthttpWatch.StartInfo.Arguments = "\c C:\Temp\WorkstationMonitor\Enable-httpwatch-v2.0.vbs"
            starthttpWatch.StartInfo.UseShellExecute = False
            starthttpWatch.StartInfo.CreateNoWindow = True
            starthttpWatch.StartInfo.UserName = strPPAccount
            starthttpWatch.StartInfo.Password = pwd
            starthttpWatch.Start()
            starthttpWatch.WaitForExit()
            starthttpWatch.Dispose()
0
Comment
Question by:chadmanvb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:chadmanvb
ID: 39999938
I see I can do this with runas, but I would prefer for the user to not enter the creds again.  I already have them do this when my aplication starts to cache the password to run other task.  This works, but I prefer a way to avoid the dialog box since I already have the user/passwork within the application

Dim procInfo As New ProcessStartInfo()
            procInfo.UseShellExecute = True
            procInfo.FileName = "CMD.exe"
            procInfo.Arguments = "/c C:\Temp\WorkstationMonitor\Enable-httpwatch-v2.0.vbs " & strWorkstation
            procInfo.WorkingDirectory = Application.StartupPath
            procInfo.Verb = "runas"
            Process.Start(procInfo)
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 40006318
You can also set the username and password properties of the ProcessStartInfo to use with RunAs.
0
 

Author Closing Comment

by:chadmanvb
ID: 40006402
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="requireAdministrator" 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.
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

634 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question