Jump to content

Working on a VBScript to install Apps...Need help.


Aen

Recommended Posts

I am doing a unattended install through Altiris. Boss wishes to have all of the applications installed through VBScript. But after the unattended install, Windows Security pops up and asks "do you really want to install....." And you need to click Run. So i found some registry keys to disable that feature, then run the install of the app, then adds the keys again to re-enable it. My problem is, is that the way i got my VBScript it basically runs the commands through a command prompt. so, it does this:

Remove key

Remove Key

install app

add key

add key

It does not wait for the app to finish installing, once it sends the command, it goes to the next line. Putting in a sleep command can waste a lot of time and i just need to figure out how for the script to know when the application is finished, it will add the keys back. I am a newb with VBScript and my coworkers just say "figure it out yourself" and i have been wasting my day away trying to figure this out. Boss is very anal and requires it a certain way and wants it so when the applications are finished, it will add the key back and not just use a wscript.sleep command.

here is my script so far. Any help would be great. I will take advice or if you want to write it lol. *shrugs*

Option Explicit
Dim objShell
Set objShell = CreateObject("Wscript.Shell")
objShell.Run "reg add ""HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3"" /v ""1806"" /t REG_DWORD /d 0 /f", 1, True
objShell.Run "reg add ""HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3"" /v ""CurrentLevel"" /t REG_DWORD /d 0 /f", 1, True
WScript.Sleep(10000)
objShell.Run "cmd /c start \\Server\e$\file.msi", 1, True
WScript.Sleep(10000)
objShell.Run "reg add ""HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3"" /v ""1806"" /t REG_DWORD /d 1 /f", 1, True
objShell.Run "reg add ""HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3"" /v ""CurrentLevel"" /t REG_DWORD /d 12000 /f", 1, True
WScript.Quit

Link to comment
Share on other sites


2 things:

WScript.Shell has methods such as RegRead, RegWrite, and RegDelete. See the docs on MSDN here. It's very simple to use, and works better. There's no need at all to use reg.exe for this (and no need for the sleep "hack" either). There's plenty of examples around if you google for it, or you can check the scripting guy's columns, or the scripting center, or various community sites, tutorials and what not. There's no shortage of resources about scripting out there.

And also, why not use silent switches on the msi installer too?

Edit: and to start a MSI installer, I wouldn't exactly use "cmd" either, but rather msiexec.

Edited by crahak
Link to comment
Share on other sites

2 things:

WScript.Shell has methods such as RegRead, RegWrite, and RegDelete. See the docs on MSDN here. It's very simple to use, and works better. There's no need at all to use reg.exe for this (and no need for the sleep "hack" either). There's plenty of examples around if you google for it, or you can check the scripting guy's columns, or the scripting center, or various community sites, tutorials and what not. There's no shortage of resources about scripting out there.

And also, why not use silent switches on the msi installer too?

Edit: and to start a MSI installer, I wouldn't exactly use "cmd" either, but rather msiexec.

heh, i have been googling a LOT last few days. And i have been just piecing together what i have found. Problem is, i dont know the best way to script this stuff. I just do a search and try to piece things together. I get tossed a project and they say "use vbscript" and i am trying to work on it best i can.

When i try to do the silent commands for msi files, it still comes up with windows security asking if i want to run the file. The whole project has to be done without human intervention and work 100% without someone touching it.

Using the regread (that you just mentioned) i can change my commands to do that, but when i launch the msi app, it still asks for that security code and still have the same issue.

Link to comment
Share on other sites

I could write that script in a couple minutes (literally). But I'm not sure what you're doing with them reg keys, in your first post you say you remove them, yet you were using reg add (which adds keys/valus), and now you're mentioning RegRead (which reads) -- nothing that deletes keys anywhere. And I don't normally mess with the IE zones too much, so not 100% sure what has to be set to what to not get those warnings on your local intranet.

If you said what it has to do in plain terms, i.e. "delete value named xyz in HKLM\Software\whatever" or "set the value named xyz to 123 at HKLM\Software\whatever" or such (and know for a fact that would work), then it would be trivial to write in just about any scripting language. It's hard writing a script for someone else when you're not even sure what it has to do.

Link to comment
Share on other sites

I could write that script in a couple minutes (literally). But I'm not sure what you're doing with them reg keys, in your first post you say you remove them, yet you were using reg add (which adds keys/valus), and now you're mentioning RegRead (which reads) -- nothing that deletes keys anywhere. And I don't normally mess with the IE zones too much, so not 100% sure what has to be set to what to not get those warnings on your local intranet.

If you said what it has to do in plain terms, i.e. "delete value named xyz in HKLM\Software\whatever" or "set the value named xyz to 123 at HKLM\Software\whatever" or such (and know for a fact that would work), then it would be trivial to write in just about any scripting language. It's hard writing a script for someone else when you're not even sure what it has to do.

Sorry, i got so many things going on at once. What it is really doing is changing 2 different registry values so windows security will no longer pop up. Then install the application. After the application installs (which is my issue, it starts it then goes to the next line) then puts the value back to what it was orginally.

When installing the application from a remote server it uses the internet settings for files, so that is why i am trying to disable those.

Link to comment
Share on other sites

Ok, this should get you mostly there then:

Const cPath1806 = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\1806"
Const cCurrentLevel = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\CurrentLevel"

Set objShell = CreateObject("WScript.Shell")

'read old values
sPath1806 = objShell.RegRead(cPath1806)
sCurrentLevel = objShell.RegRead(cCurrentLevel)

'set temp values
objShell.RegWrite cPath1806, 0, "REG_DWORD"
objShell.RegWrite cCurrentLevel, 0, "REG_DWORD"

'run program
objShell.Run "msiexec /i \\Server\e$\file.msi /qb", 1, True

'restore old values
objShell.RegWrite cPath1806, sPath1806, "REG_DWORD"
objShell.RegWrite cCurrentLevel, sCurrentLevel, "REG_DWORD"

I haven't actually tested running an installer from a network share mind you, so you might have to play with that part (setting reg values is tested though). I put in some comments, so it should be fairly simple to understand.

Link to comment
Share on other sites

Ok, this should get you mostly there then:

Const cPath1806 = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\1806"
Const cCurrentLevel = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\CurrentLevel"

Set objShell = CreateObject("WScript.Shell")

'read old values
sPath1806 = objShell.RegRead(cPath1806)
sCurrentLevel = objShell.RegRead(cCurrentLevel)

'set temp values
objShell.RegWrite cPath1806, 0, "REG_DWORD"
objShell.RegWrite cCurrentLevel, 0, "REG_DWORD"

'run program
objShell.Run "msiexec /i \\Server\e$\file.msi /qb", 1, True

'restore old values
objShell.RegWrite cPath1806, sPath1806, "REG_DWORD"
objShell.RegWrite cCurrentLevel, sCurrentLevel, "REG_DWORD"

I haven't actually tested running an installer from a network share mind you, so you might have to play with that part (setting reg values is tested though). I put in some comments, so it should be fairly simple to understand.

Thanks! I got to look at why it says my MSI is not a valid windows installation package.

Link to comment
Share on other sites

that script has the same issue as my last one. It changes the registery which is good, then kicks off the install then right that second it turns back off that key. How do i get it so when the install is finished, it will put the keys back to way its supposed to be?

Link to comment
Share on other sites

then kicks off the install then right that second it turns back off that key

Then it's an issue with WSH or such, because it's supposed to wait, and it does wait then I try it (with another process at least). Or maybe msiexec spawns another process and terminates almost instantly, and then the script continues, in which case a short delay would work (or waiting for the install to be finished)...

Link to comment
Share on other sites

then kicks off the install then right that second it turns back off that key

Then it's an issue with WSH or such, because it's supposed to wait, and it does wait then I try it (with another process at least). Or maybe msiexec spawns another process and terminates almost instantly, and then the script continues, in which case a short delay would work (or waiting for the install to be finished)...

its kinda weird. I just tried with a different MSI install and it worked the way its supposed to. I am going to rebuild it.

Thanks again for your insight and help :)

Link to comment
Share on other sites

I don't like messing with the zones, so when I have installs running from network locations, I use a self-extracting 7zip package. That allows you to run the install from the network, but the install itself is run on the local system, and then deleted after the fact.

Link to comment
Share on other sites

I don't like messing with the zones, so when I have installs running from network locations, I use a self-extracting 7zip package. That allows you to run the install from the network, but the install itself is run on the local system, and then deleted after the fact.

we are going to be using MSI files to later to deploy with Altiris once that gets all the way up and going. I will check out 7zip's self extracting though. That may help on a few things.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...