Custom MSI, backup and restore file

I am trying to build a custom MSI using Advanced Installer.  I have a file C:\Program Files\Streamware\Vendmax\VendMax.ini that I need to backup before the install and restore after.

I have tried doing this with a VBscript that runs at initialization and another that runs at commit time through custom actions.

The first script just grabs the ini and copies it to the %temp% directory.  This works fine; the problem comes when I try to copy the file back.  I get an access denied error because elevation is required to restore this file to the Program Files directory per UAC.

I tried to change the script so it prompts for UAC which works great if I run it outside the windows installer, however, when I try to install it fails at commit time with a "Microsoft VBScript runtime error: Object required: 'WScript' Line 1, Column 1"

It doesn't like my WScript.Arguments.length, If I remove that I get another error when I call WScript.ScriptFullName.

Am I going about this the wrong way or is there something I should change in my scripts to get them to work with UAC?  The same script has to set a full full trust in .net as well which also requires UAC.  When the install starts I do get a UAC prompt but it must not keep the elevation through the whole install process.  
'~~~~~~SCRIPT THAT FAILS WITH ACCESS DENIED, Fails Line 10~~~~~~~~
Set fso = CreateObject("Scripting.FileSystemObject")
Set wshell = CreateObject("WScript.Shell")
strTemp = WShell.ExpandEnvironmentStrings("%TEMP%")
If fso.FolderExists("C:\Program Files (x86)") Then
	strIniLoc = "C:\Program Files (x86)\Streamware\VendMax"
Else
	strIniLoc = "C:\Program Files\Streamware\VendMax"
End If
If fso.FileExists (strTemp & "\VendMax4.ini") Then
	fso.CopyFile strTemp & "\Vendmax4.ini",strIniLoc & "\VendMax.ini",True
End If
strWinDir = WShell.ExpandEnvironmentStrings("%WINDIR%")
wshell.Run strWinDir & "\Microsoft.NET\Framework\v2.0.50727\caspol.exe -q -m -ag All_Code -zone Intranet FullTrust"

'~~~~~SCRIPT THAT FAILS WITH OBJECT REQUIRED Line 1~~~~~
If WScript.Arguments.length =0 Then
	Set objShell = CreateObject("Shell.Application")
  	objShell.ShellExecute "wscript.exe", Chr(34) & _
  	WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
Else
	Set fso = CreateObject("Scripting.FileSystemObject")
	Set wshell = CreateObject("WScript.Shell")
	strTemp = WShell.ExpandEnvironmentStrings("%TEMP%")
	If fso.FolderExists("C:\Program Files (x86)") Then
		strIniLoc = "C:\Program Files (x86)\Streamware\VendMax"
	Else
		strIniLoc = "C:\Program Files\Streamware\VendMax"
	End If
	If fso.FileExists (strTemp & "\VendMax4.ini") Then
		fso.CopyFile strTemp & "\Vendmax4.ini",strIniLoc & "\VendMax.ini",True
	End If
	strWinDir = WShell.ExpandEnvironmentStrings("%WINDIR%")
	wshell.Run strWinDir & "\Microsoft.NET\Framework\v2.0.50727\caspol.exe -q -m -ag All_Code -zone Intranet FullTrust"

End If

Open in new window

LVL 22
mcsweenSr. Network AdministratorAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
mcsweenConnect With a Mentor Sr. Network AdministratorAuthor Commented:
I have resolved this issue.  I had to set the impersonation level to none where the custom action script was defined.  This allows it to run under the windows installer elevated permissions already granted at the start of the install.  Used my first script where I was getting access denied.  Works perfectly now.
0
 
Justin EllenbeckerIT DirectorCommented:
Maybe this will work?  It converts the vbs to an exe which fires off the UAC.
http://www.vbs2exe.com/
0
 
zoofanCommented:
Drawing at straws here trying to piece together pieces of pieces, but

"If WScript.Arguments.length =0 Then " ERRORS TO OBJECT REQUIRED

My first thought would be:
What is the default scripting engine set to? cscript or wscript and/or  how is the msi starting your script, cscript or wscript?


It would seem to me, that an error of "OBJECT REQUIRED" on that command as line 1, implies that wscript is not being used (hence the missing object).


Just a thought

zf
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
zoofanCommented:
Setting the default scripting engine:

http://support.microsoft.com/kb/245254







zf
0
 
AbqBillCommented:
You can't use the 'WScript' object in a custom action script in an MSI. Bill.
0
 
mcsweenSr. Network AdministratorAuthor Commented:
AbqBill

Any idea how I can accomplish what needs to be done in the script without the wscript object?  This is the only way I know how to trigger UAC from VBScript.  I'm open to other methods beside VBS if you have any suggestions.

StrifeJester

This app did not work for me
0
 
AbqBillCommented:
Hi, please detail what the script does and what you're trying to accomplish. Bill.
0
All Courses

From novice to tech pro — start learning today.