Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 315
  • Last Modified:

How to run a VB Script that will execute an install using RUN AS administrator?


I am totally noob in terms of any scripting!

I need to initiate an EXE within a citrix published desktop environment when a users logs that will RUN AS administrator.  It needs to work the same way if you were going to right click the EXE and select RUN AS and enter credentials.

I thought I could setup a Group Policy to initiate the script at log-on but then i realize i know nothing about VB Script!  Is this difficult?

Filename:   123.exe
0
LenCepeda
Asked:
LenCepeda
2 Solutions
 
LenCepedaAuthor Commented:
I forgot to mention the most important part of the script.  

When the installtion is executed, it will determine that the program is already installed and the user will be prompted to either REPAIR or REMOVE the application.  I need the REPAIR options selected.  Is this possible?
0
 
Robberbaron (robr)Commented:
dont believe so as the RUN AS problem arises requiring admin user interaction or storage of the password within the script/batch file.


However, scripts that run as part of GPO "windows Startup" , run before user logs on and as the SYSTEM user. Hence have access to the entire system, but NOT to a users profile.

I have a script that installs  dll's this way. (until 64bit dll caused issues). note that all source files must be either already on the local system or on the SYSVOL share so that the startup script has access

-------------------------------------------------	
'script to copy & install dsofile to each PC

''''''''''''''''''''''''''''''''''
' Constants for opening files
''''''''''''''''''''''''''''''''''
Const OpenFileForReading = 1
Const OpenFileForWriting = 2
Const OpenFileForAppending = 8


'--- set up files & log ---------
const ScrFldr="\\thor\SYSVOL\me.com.au\scripts\"       'std source location

const LogFldr="\\thir\SYSVOL\me.com.au\logs\"       

	dim a, src , sVers
	dim fs
	src="dsofile.dll"
	lf = "installs.log"
	sVers=""
	Set oNet = CreateObject("WScript.Network")

	datetime=Year(now()) & Right("0" & Month(now()), 2) & Right("0" & Day(now()), 2) & "=" & Right("0" & Hour(now()), 2) & Right("0" & Minute(now()), 2) '& Right("0" & Second(now()), 2)

	Set fso = CreateObject("Scripting.FileSystemObject")  
	sysfld = fso.GetSpecialFolder(1)    'the system folder
	winfld =  fso.GetSpecialFolder(0)   'the windows folder

	' write to Log 
	Set flf = fso.GetFile(logfldr & lf)
	Set tslf = flf.OpenAsTextStream(OpenFileForAppending)

	tslf.Write (Onet.ComputerName & " , " & "BEGIN" & " , " & Datetime & vbCrLf)
'------- end setup section ----
	msg=""
'----copy dsofile if not exist --------------
  sVers="--"
	If (fso.FileExists(winfld & "\" & src )) Then
    		msg = "dsofile exists."
		sVers = fso.GetFileVersion(winfld & "\" & src )
		msg = msg & " v=" & sVers
	end if
	'msgbox ("vers" & msg)
	
	if left(sVers,6) = "2.1.28" then    
		'no action needed      should be 2.1.2841
	Else
		set f1 = fso.GetFile( scrfldr & src )
		f1.Copy winfld & "\" & src,True
		a=(sysfld & "\regsvr32.exe /S " & winfld & "\" & src )

		CreateObject("Wscript.Shell").Run a
		msg = msg & " Install dsofile "
		'msgbox("dsofile done")
	
	End If

'--- write to log file -----
	tslf.Write (Onet.ComputerName & " , " & msg & " , " & Datetime & vbCrLf)
	tslf.Close
'------ end ---
	set onet = nothing
	Set FSO = Nothing

Open in new window

0
 
RobSampsonCommented:
Hi there, if you put your username and password into the script, it should do the job as a logon script.

There is the obvious security risk involved with elevating rights like this though.....a VBS is a plain text file.

Regards,

Rob.
strEXE = "\\server\share\123.exe"
strPSExec = "\\server\share\psexec.exe"
strUser = "domain\administrator"
strPassword = "Y0urP@ssw0rd"

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network")
strEXE = objFSO.GetFile(strEXE).ShortPath
strPSExec = objFSO.GetFile(strPSExec).ShortPath
strCommand = strPSExec & " -accepteula -u " & strUser & " -p " & strPassword & " \\" & objNetwork.ComputerName & " " & strEXE & " /fa /qb"
objShell.Run strCommand, 1, True

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now