Hi all,

I am trying to create a VB script which I can assign as a startup script
which will perform the following functions:

Check using Win32_Product for a software version 1 and if it exists
uninstall it
Check using Win32_Product for a software version 2 and if it exists
uninstall it
Install using Win32_Product software version 3

I have created the script and it works fine when I am logged in and double
click the vbs file. When I assign it as a start up script the machine takes
an extra 10 mins to start up!

Here is the code:

option explicit
dim strComputer
dim objWMIService
dim objSoftware
dim colSoftware
dim objService
dim objSoftware2
dim errReturn

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colSoftware = objWMIService.ExecQuery _
("Select name from Win32_Product Where Name = 'Name1")

For Each objSoftware in colSoftware
objSoftware.Uninstall()
Next

Set colSoftware = objWMIService.ExecQuery _
("Select name from Win32_Product Where Name = 'Name2'")

For Each objSoftware in colSoftware
objSoftware.Uninstall()
Next

Const ALL_USERS = True
Set objService = GetObject("winmgmts:")
Set objSoftware2 = objService.Get("Win32_Product")
errReturn = objSoftware2.Install("\\server\share$\software.msi", , ALL_USERS)

And here is what I get on the userenv.log around the slow time...

USERENV(244.240) 18:12:16:359 LoadProfileInfo: Failed to query central
profile with error 2
USERENV(244.240) 18:12:16:359 GetProfileType: ProfileFlags is 0
USERENV(2e0.2f0) 18:12:16:484 LibMain: Process Name:
C:\WINDOWS\System32\WScript.exe
USERENV(90.578) 18:12:16:515 ImpersonateUser: Failed to impersonate user
with 5.
USERENV(90.578) 18:12:16:515 GetUserNameAndDomain Failed to impersonate user
USERENV(90.578) 18:12:16:531 GetUserDNSDomainName: Domain name is NT
Authority. No DNS domain name available.
USERENV(90.4b0) 18:12:16:609 GetProfileType: Profile already loaded.
USERENV(90.4b0) 18:12:16:609 LoadProfileInfo: Failed to query central
profile with error 2
USERENV(90.4b0) 18:12:16:609 GetProfileType: ProfileFlags is 0
USERENV(914.918) 18:12:18:828 LibMain: Process Name:
C:\WINDOWS\system32\wbem\wmiprvse.exe
USERENV(938.93c) 18:12:19:031 LibMain: Process Name:
C:\WINDOWS\system32\msiexec.exe
USERENV(a28.a2c) 18:12:57:870 LibMain: Process Name:
C:\WINDOWS\system32\wuauclt.exe
USERENV(a78.a7c) 18:12:58:637 LibMain: Process Name:
C:\WINDOWS\system32\wbem\wmiprvse.exe
USERENV(bd8.bdc) 18:13:16:325 LibMain: Process Name:
C:\WINDOWS\system32\userinit.exe
USERENV(df0.df4) 18:21:21:091 LibMain: Process Name:
C:\WINDOWS\system32\MsiExec.exe
USERENV(e3c.e40) 18:21:28:187 LibMain: Process Name:
C:\WINDOWS\System32\WScript.exe
USERENV(ea4.ea8) 18:21:37:769 LibMain: Process Name:
C:\WINDOWS\system32\mpnotify.exe
USERENV(5d8.5dc) 18:21:37:815 LoadUserProfile: Yes, we can impersonate the
user. Running as self

Note the massive gap... I have put in various wscript.echo points along the
code to see where it is slowing but cannot seem to fix it... I need this to
be a system startup script because the users who login will not have enough
rights to perform this task... is there some kind of impersonation problem,
or is something not loading in the right order?? I am pretty stuck at this
point to be honest...

Re: Win32_Product slow startup script? by Owen

Owen
Mon Feb 04 17:17:32 CST 2008

On Feb 1, 10:52=A0am, UselessUser
<UselessU...@discussions.microsoft.com> wrote:
> Hi all,
>
> I am trying to create a VB script which I can assign as a startup script
> which will perform the following functions:
>
> Check using Win32_Product for a software version 1 and if it exists
> uninstall it
> Check using Win32_Product for a software version 2 and if it exists
> uninstall it
> Install using Win32_Product software version 3
>
> I have created the script and it works fine when I am logged in and double=

> click the vbs file. When I assign it as a start up script the machine take=
s
> an extra 10 mins to start up!
>
> Here is the code:
>
> option explicit
> dim strComputer
> dim objWMIService
> dim objSoftware
> dim colSoftware
> dim objService
> dim objSoftware2
> dim errReturn
>
> strComputer =3D "."
>
> Set objWMIService =3D GetObject("winmgmts:" _
> & "{impersonationLevel=3Dimpersonate}!\\" & strComputer & "\root\cimv2")
>
> Set colSoftware =3D objWMIService.ExecQuery _
> =A0 =A0 ("Select name from Win32_Product Where Name =3D 'Name1")
>
> For Each objSoftware in colSoftware
> =A0 =A0 objSoftware.Uninstall()
> Next
>
> Set colSoftware =3D objWMIService.ExecQuery _
> =A0 =A0 ("Select name from Win32_Product Where Name =3D 'Name2'")
>
> For Each objSoftware in colSoftware
> =A0 =A0 objSoftware.Uninstall()
> Next
>
> Const ALL_USERS =3D True
> Set objService =3D GetObject("winmgmts:")
> Set objSoftware2 =3D objService.Get("Win32_Product")
> errReturn =3D objSoftware2.Install("\\server\share$\software.msi", , ALL_U=
SERS)
>
> And here is what I get on the userenv.log around the slow time...
>
> USERENV(244.240) 18:12:16:359 LoadProfileInfo: =A0Failed to query central
> profile with error 2
> USERENV(244.240) 18:12:16:359 GetProfileType: ProfileFlags is 0
> USERENV(2e0.2f0) 18:12:16:484 LibMain: Process Name: =A0
> C:\WINDOWS\System32\WScript.exe
> USERENV(90.578) 18:12:16:515 ImpersonateUser: Failed to impersonate user
> with 5.
> USERENV(90.578) 18:12:16:515 GetUserNameAndDomain Failed to impersonate us=
er
> USERENV(90.578) 18:12:16:531 GetUserDNSDomainName: =A0Domain name is NT
> Authority. =A0No DNS domain name available.
> USERENV(90.4b0) 18:12:16:609 GetProfileType: =A0Profile already loaded.
> USERENV(90.4b0) 18:12:16:609 LoadProfileInfo: =A0Failed to query central
> profile with error 2
> USERENV(90.4b0) 18:12:16:609 GetProfileType: ProfileFlags is 0
> USERENV(914.918) 18:12:18:828 LibMain: Process Name: =A0
> C:\WINDOWS\system32\wbem\wmiprvse.exe
> USERENV(938.93c) 18:12:19:031 LibMain: Process Name: =A0
> C:\WINDOWS\system32\msiexec.exe
> USERENV(a28.a2c) 18:12:57:870 LibMain: Process Name: =A0
> C:\WINDOWS\system32\wuauclt.exe
> USERENV(a78.a7c) 18:12:58:637 LibMain: Process Name: =A0
> C:\WINDOWS\system32\wbem\wmiprvse.exe
> USERENV(bd8.bdc) 18:13:16:325 LibMain: Process Name: =A0
> C:\WINDOWS\system32\userinit.exe
> USERENV(df0.df4) 18:21:21:091 LibMain: Process Name: =A0
> C:\WINDOWS\system32\MsiExec.exe
> USERENV(e3c.e40) 18:21:28:187 LibMain: Process Name: =A0
> C:\WINDOWS\System32\WScript.exe
> USERENV(ea4.ea8) 18:21:37:769 LibMain: Process Name: =A0
> C:\WINDOWS\system32\mpnotify.exe
> USERENV(5d8.5dc) 18:21:37:815 LoadUserProfile: Yes, we can impersonate the=

> user. Running as self
>
> Note the massive gap... I have put in various wscript.echo points along th=
e
> code to see where it is slowing but cannot seem to fix it... I need this t=
o
> be a system startup script because the users who login will not have enoug=
h
> rights to perform this task... is there some kind of impersonation problem=
,
> or is something not loading in the right order?? I am pretty stuck at this=

> point to be honest...

If a "startup script" (not interactively run) it may be having trouble
resolving the network location you gave it for installing the MSI. It
seems you have several profile related errors in your log. Plus, you
say the script runs fine if you log on and run it interactively by
clicking it. Also, I'd use the ProductCode (or IdentifyingNumber in
WMI) instead of Name to detect the old versions, as you have in your
script. A product can keep the same across versions; the ProductCode
will always be unique.

See if you can run the script after the user profile is loaded. Is a
logon script an option? I've done the exact thing you're describing,
but with a logon script (the pain there was doing "runas" for those
installations because the users were not admins). GPO?

-OG