Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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

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 & exefileaccount = 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.quitFunction 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

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

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!

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

![]() |
![]() |
![]() |

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