Computing.Net > Forums > Programming > Run a file as local administrator

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Run a file as local administrator

Reply to Message Icon

Name: xscript
Date: October 11, 2004 at 04:35:58 Pacific
OS: Windows XP
CPU/Ram: NA
Comment:

Hi,

Is there a way in vb or vbscript to run an application or script with local administrator rights when the currently logged in user does not have admin rights?

I want to put a vbs (or alternatively a compiled VB Application) into a login script to add a registry key. This can only be done with local admin rights and I have over 200 PC's to do this to. I don't want to have to go to each PC and login as an administrator.

I have searched google and I can't find this funcionality in VB.

Many Thanks

Xscript



Sponsored Link
Ads by Google

Response Number 1
Name: zoddy
Date: October 11, 2004 at 10:59:32 Pacific
Reply:

if you right click on the application icon
and select properties, theres an option to
run as a different user.

A+ Certified
MCSE soon


0

Response Number 2
Name: xscript
Date: October 11, 2004 at 11:47:07 Pacific
Reply:

Thanks, but this doesn't solve my problem.

I need to add a registry key on loads of 2000/XP machines.

There is not a 'Run As' on the list of options for .reg or .bat files, but even if there was, it wouldn't help because the setting isn't saved for every execution.

Somebody out there must work in an environment where the users do not have admin rights on the PC's they use (Colleges / Universities), where fixes, updates need to be added.

I've thought about using WMI, but this isn't any good because we are running unix and netware servers, not Microsoft, only the clients are microsoft.

The best solution I have found so far is to use the shell and sendkeys command in vbs to automate the process of using the runas at the command prompt, but this is rather messy, crude and prone to failure because if this is done at the login script, the PC may not be initialised fully enough to open a command prompt window and run through the process of running an application.

This is the wacky bit of code that I am using but I can't really implement it because of the above issues.

cmdpath = "\System32\cmd.exe"
adminuser = "administrator"
password = "the-pwd-here"
exefile = "EXE FILE HERE"
CRLF = chr(10) & chr(13)

Set WshNetwork = WScript.CreateObject("WScript.Network")

Set WshShell = WScript.CreateObject("WScript.Shell")

Set WshSysEnv = WshShell.Environment("PROCESS")

windir = WshSysEnv("WINDIR")
cmdpath = windir & cmdpath
computer = WshNetwork.ComputerName
'domain = WshNetwork.UserDomain
directory = get_current_directory
fullpath = directory & exefile

account = computer & "\" & adminuser

WshShell.Run cmdpath
WScript.Sleep 150
WshShell.AppActivate cmdpath
WScript.Sleep 150
WshShell.SendKeys "runas /user:" & account & " " & chr(34) & fullpath & chr(34) & CRLF
WScript.Sleep 230
WshShell.SendKeys password & CRLF
WScript.Sleep 70
WshShell.SendKeys "exit" & CRLF
wscript.quit

Function get_current_directory()


directory = WScript.ScriptFullName
pos = instrrev(directory,"\",-1)
final_directory = left(directory,pos)

get_current_directory = final_directory

Set WshShell = Nothing

End Function

.............................

Any help would be a godsend!!

xscript


0

Response Number 3
Name: zoddy
Date: October 11, 2004 at 17:10:02 Pacific
Reply:

i've seen files with extension .reg that'll add a reg key. put your reg key entry into this format?

A+ Certified


0

Response Number 4
Name: nickc
Date: November 9, 2004 at 03:11:34 Pacific
Reply:

Bloody hell, zoddy! Do you actually know ANYTHING about computers? Go read PCs for Dummies or something!!!!

You shouldn't be trying to help people with problems when your knowledge seems to extend no further than that of your average pensioner!


0

Response Number 5
Name: Scotts
Date: November 24, 2004 at 11:22:03 Pacific
Reply:

Nick

Did you ever figure this out? I have the same situation. Other than running a program like "psexec.exe" I have not found a solutiion.

Thanks


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Run a file as local administrator

running batch file as local admin www.computing.net/answers/programming/running-batch-file-as-local-admin/17444.html

run perl script as diffrent user www.computing.net/answers/programming/run-perl-script-as-diffrent-user/17204.html

Linux: Sending a file as STDIN www.computing.net/answers/programming/linux-sending-a-file-as-stdin/8658.html