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

Run a file as local administrator

Reply to Message Icon

Original Message
Name: xscript
Date: October 11, 2004 at 04:35:58 Pacific
Subject: Run a file as local administrator
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


Report Offensive Message For Removal

Response Number 1
Name: zoddy
Date: October 11, 2004 at 10:59:32 Pacific
Subject: Run a file as local administrator
Reply: (edit)

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

A+ Certified
MCSE soon


Report Offensive Follow Up For Removal

Response Number 2
Name: xscript
Date: October 11, 2004 at 11:47:07 Pacific
Subject: Run a file as local administrator
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 3
Name: zoddy
Date: October 11, 2004 at 17:10:02 Pacific
Subject: Run a file as local administrator
Reply: (edit)

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

A+ Certified


Report Offensive Follow Up For Removal

Response Number 4
Name: nickc
Date: November 9, 2004 at 03:11:34 Pacific
Subject: Run a file as local administrator
Reply: (edit)

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!


Report Offensive Follow Up For Removal

Response Number 5
Name: Scotts
Date: November 24, 2004 at 11:22:03 Pacific
Subject: Run a file as local administrator
Reply: (edit)

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


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Run a file as local administrator

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software