Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to start a batch file with domain administrator access without UAC prompt.
Here my code. Im getting error at process.start().

What I have tried:

Dim proc As Process = Nothing
            Dim batDir As String = String.Format("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\")
            proc = New Process()
            proc.StartInfo.WorkingDirectory = batDir
            proc.StartInfo.FileName = "test.bat"
            proc.StartInfo.Verb = "runas" 'add this to prompt for elevation
            proc.StartInfo.UserName = "admin"
            proc.StartInfo.Domain = "sun.ad"
            proc.StartInfo.Password = theSecureStringPassword
            proc.StartInfo.UseShellExecute = False
            proc.StartInfo.CreateNoWindow = False
            proc.StartInfo.RedirectStandardOutput = True
            proc.StartInfo.RedirectStandardError = True
            proc.Start()
            proc.WaitForExit()
            MessageBox.Show("Bat file executed !!")
Posted
Updated 3-Feb-21 15:25pm

1 solution

Quote:
without UAC prompt.

Not going to happen.

If UAC is enabled, it is there to specifically let you know admin credentials are required and must be typed in to acknowledge that it's OK to use them.
 
Share this answer
 
Comments
Member 12303942 3-Feb-21 21:36pm    
I need to run this at non-admin user computer. Is there any other option ?
Dave Kreskowiak 3-Feb-21 21:43pm    
You could use WMI and the Win32_Process class to launch the process remotely, but you're still going to need admin credentials to connect to the remote machine.

Create method of the Win32_Process class - Win32 apps | Microsoft Docs[^]

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