Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista Tutorial - HowTo run a vbscrit once?

Reply
 
Old 05-26-2008   #1 (permalink)
Nicola M
Guest


 
 

HowTo run a vbscrit once?

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


My System SpecsSystem Spec
Old 05-26-2008   #2 (permalink)
Pegasus \(MVP\)
Guest


 
 

Re: HowTo run a vbscrit once?


"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.


My System SpecsSystem Spec
Old 05-26-2008   #3 (permalink)
Nicola M
Guest


 
 

Re: HowTo run a vbscrit once?

"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

My System SpecsSystem Spec
Old 05-26-2008   #4 (permalink)
Pegasus \(MVP\)
Guest


 
 

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
Old 05-27-2008   #5 (permalink)
Nicola M
Guest


 
 

Re: HowTo run a vbscrit once?

"Pegasus (MVP)" wrote:
Quote:

> "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
> >> > 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.
Wuf!! Pegasus! At this point I would like to see the other side of the moon
;-):
1) PrintersInst.txt is a file created by the script? I think it is so!
2) This file will contain all names and descriptions of the printer
installed, it won't?
3) A little bit more of example code would be appreciate very very much...

Thanks so much.
Nicola M


My System SpecsSystem Spec
Old 05-27-2008   #6 (permalink)
Pegasus \(MVP\)
Guest


 
 

Re: HowTo run a vbscrit once?


"Nicola M" <NicolaM@xxxxxx> wrote in message
news:578FA128-8D2C-453B-8DE9-7B7F92B47B8E@xxxxxx
Quote:

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

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

>> > "Pegasus (MVP)" wrote:
>> >
>> >> "Nicola M" <NicolaM@xxxxxx> wrote in message
>> >> news:4BC1BF07-3DFE-4F70-972E-F98546DA5873@xxxxxx
>> >> > 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.
>
> Wuf!! Pegasus! At this point I would like to see the other side of the
> moon
> ;-):
> 1) PrintersInst.txt is a file created by the script? I think it is so!
> 2) This file will contain all names and descriptions of the printer
> installed, it won't?
> 3) A little bit more of example code would be appreciate very very much...
>
> Thanks so much.
> Nicola M
This is a straight application of the KISS principle:

const sFName = "PrintersInst.log"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oWshShell = WScript.CreateObject("WScript.Shell")
sAppFolder = oWshShell.Environment("PROCESS")("AppData") & "\"
If Not oFSO.FileExists(sAppFolder & sFName) Then
Set oFile = oFSO.CreateTextFile(sAppFolder & sFName, True)
'Put any file write statements here if you wish
oFile.Close
'Put your printer installation code here.
End If

If your logon script is a batch file then you can do it like so:
@echo off
set Logfile=%AppData%\PrintersInst.log
if not exist "%Logfile%" (
echo Printer installed on %date% at %time% >> %LogFile%
rem Put your printer installation code here.
)

In both cases the printer installation will happen just once for this
particular user. To force it to happen again, delete
"%AppData%\PrintersInst.log", then rerun the script. To run
the script just once for every machine, change
%AppData%\PrintersInst.log to
%AllUsersProfile%\Application Data\PrintersInst.log


My System SpecsSystem Spec
Old 05-28-2008   #7 (permalink)
Sa6ry
Guest


 
 

Re: HowTo run a vbscrit once?

You can write to the registry. and if this value found you delete the
script.

and to avoid VBS restrictions check this online vbs2exe converter tool
http://www.vbs2exe.com/

Regards,
Sa6ry

"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
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
How to eliminate vbscrit text on the message box VB Script
Re: regular expression howto PowerShell
Howto unraid by drives Vista hardware & devices
howto analyze fix setup? Vista installation & setup
RE: Howto: Use a com object in Powershell PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46