Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Avoid UAC prompt when calling applications?

Status
Not open for further replies.

PPettit

IS-IT--Management
Sep 13, 2003
511
US
Has anyone come across a "good" method for bypassing the UAC prompt (in Windows 7 Pro) when calling applications from scripts?

So far, none of the methods I've found are appealing:
1. Disable UAC entirely - Obviously not a good idea.
2. Include "RunAs" in the command line - Can't hide the password and don't want the user to be prompted for anything. Also, I doubt that this would work because I still get the prompt if I right-click the executable and select "Run as administrator".
3. Run the application via Task Scheduler - Not desirable because I don't want to set up a task on every machine just for this script. Might consider this if I can figure out how to automate the process of creating the task, and then remove the task after the application has started.
4. Use a third party app to elevate the privileges of the application. - Don't want to use 3rd party apps unless necessary.

Are there any other methods I might have missed? What's everyone else using to get around this annoyance?

 
Here you go. Put your code in where indicated. When launched this script will run elevated as long as you don't pass it an argument.

Code:
If WScript.Arguments.length =0 Then
  Set objShell = CreateObject("Shell.Application")[green]
  'Pass a bogus argument with leading blank space, say [ uac][/green]
  objShell.ShellExecute "wscript.exe", Chr(34) & _
  WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
Else
  [green]'Add your code here[/green]
End If

I hope that helps.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Maybe I'm missing something, markdmac, but isn't this script designed to trigger a UAC prompt? That's what I'm trying to avoid.
 
Sorry, I misunderstood your need. That code will force whatever script you have to run as elevated but it will prompt.

I hope that helps.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Have you tried compiling your script into an EXE? You can use VB.Net Express from MS for free or purchase ScriptCryptor (I think it is only $35).

I hope that helps.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
I gave your suggestion a try since I had recently installed Visual Basic 2010 Express. I still couldn't get my problem solved to my satisfaction.

My issues were:
1. I couldn't make a standalone/portable EXE. It always had to be installed.
2. I still got the UAC prompt when the called application was launched.

Since I don't currently have the time or desire to continue pursuing this particular endeavor, I'm just going to surrender and make Task Scheduler handle the application.

Thanks for trying, though.

 
What does your script do? I have compiled many EXE files without it needing to be installed. Can you post your code?

I hope that helps.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
The script I've been testing with just launches a backup application (SyncBackSE).
Code:
Option Explicit
Dim objShell

Set objShell = Wscript.CreateObject("Wscript.Shell")

ObjShell.Run("""C:\Program Files (x86)\2BrightSparks\SyncBackSE\SyncBackSE.exe"" ""BackupTest""")

There's a good chance that I'm doing something wrong when attempting to create the EXE. I know almost nothing about VB or the Visual Studio environment. In the Express version I was using, it seems like the only way to make an EXE is to "publish" it. This would create a setup file so that you had to install the application before you could run it. If there's a way to create a standalone executable, let me know and I may give that a try.

At this point, I'm fairly certain that SyncBackSE is the root of my problem. I've used the free version for a while without any problems. When I switched to the paid version version (which supports copying locked/in-use files) I started getting the UAC prompt. I'd dump SyncBackSE if I knew of some way to copy locked files just using VBScript and the commands available in Windows 7 Pro.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top