View Single Post
Old 05-26-2008   #4 (permalink)
Pegasus \(MVP\)


 
 

Re: HowTo run a vbscrit once?


"Nicola M" <NicolaM@xxxxxx> wrote in message
news:0215124E-0898-4772-B7B8-3FA0BD9FEC65@xxxxxx
Quote:

> "Pegasus (MVP)" wrote:
>
Quote:

>>
>> "Nicola M" <NicolaM@xxxxxx> wrote in message
>> news:4BC1BF07-3DFE-4F70-972E-F98546DA5873@xxxxxx
Quote:

>> > Hi all and sorry in advance for my English.
>> >
>> > I wrote a vbs script to manage network printers. This script deletes
>> > all
>> > network printers installed on a client and then install devices
>> > indicated
>> > in
>> > the script, only.
>> > It's possible that an user connect printers not listed in the script,
>> > manually.
>> > The script is distributed by group policy in a W2K Active Directory
>> > Environment so it runs at every user logon.
>> > So: to avoid deleting and installing printers at every logon what do i
>> > do
>> > to
>> > get script runs once?
>> >
>> > Thanks.
>> > Nicola M
>> >
>>
>> Here are a couple options:
>> - You could invoke it via the RunOnce registry key.
>> - You could get the script to create a "semaphore" file
>> to signal that the script has run once before.
>
> The first one is more suitable. But... how can I put the invocation of the
> script in that registry Key?
> So, with vbs there's no a limit accessing registry? I use VBA also and I
> can
> write and read from HKEY_CURRENT_USER\Software\VB and VBA Program
> Settings\
> only.
> Thanks.
> Nicola M
You could run this script, provided that the user has appropriate
access rights to his RunOnce key:
Set WshShell = WScript.CreateObject("WScript.Shell")
bKey =
"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce\PrinterInst"
WshShell.RegWrite bKey, "c:\Windows\PInstall.vbs"

Although you may prefer this method, it is actually more
laborious than using a semaphore file, because it requires
two steps:
Step 1 - Put the key into the registry.
Step 2 - Let the user log on to execute the script.
It is also harder to test and debug.

With a semaphore file you could do it in one fell swoop:
- Check if %UserProfile%\PrinterInst.txt exists.
- If it does, don't do anything.
- If it does not, create it and run the printer installation.
Furthermore, if the installation should fail then you could
delete the semaphore file from your console. Recreating
the HKCU\RunOnce key from your console is much harder.


My System SpecsSystem Spec