Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


call a .reg file from VBS, how?

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,26117
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> call a .reg file from VBS, how?
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 call a .reg file from VBS, how? - 9/20/2005 4:27:15 PM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
i know how to call a cmd file and a vbs file but how do you call up a .reg file?

thanks in advance!
 
 
Post #: 1
 
 RE: call a .reg file from VBS, how? - 9/20/2005 4:54:32 PM   
  x0000FF

 

Posts: 5
Score: 0
Joined: 9/19/2005
Status: offline
vbscript has alot of powerful features for registry editing ....  but a very simple way to execute a .reg file is:


      


if you run that with say .... wscript.run, it'll import the data from that .reg file without prompting the user with an **** warning





(but you should go read up on regwrite)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsmthregwrite.asp

< Message edited by x0000FF -- 9/20/2005 4:56:54 PM >

(in reply to kracksmith)
 
 
Post #: 2
 
 RE: call a .reg file from VBS, how? - 9/20/2005 4:55:56 PM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
i guess this would work:

WshShell.run "regedit /S c:\vptray.reg",1,True


But it seems like it's showing a cmd screen. what switches do i need to hide this window??

(in reply to kracksmith)
 
 
Post #: 3
 
 RE: call a .reg file from VBS, how? - 9/20/2005 5:07:48 PM   
  x0000FF

 

Posts: 5
Score: 0
Joined: 9/19/2005
Status: offline
this doesn't bring up a cmd window


      



there's no way to hide a normal cmd.exe window.   But if you're interested, most people use an alternative called cmdow,  it's a great utility:   http://www.commandline.co.uk/cmdow/

(in reply to kracksmith)
 
 
Post #: 4
 
 RE: call a .reg file from VBS, how? - 9/20/2005 11:31:31 PM   
  Country73


Posts: 712
Score: 8
Joined: 8/25/2004
From: USA
Status: offline
You could also just change
    WshShell.run "regedit /S c:\vptray.reg",1,True
to
    WshShell.run "regedit /S c:\vptray.reg",0,True

(in reply to kracksmith)
 
 
Post #: 5
 
 RE: call a .reg file from VBS, how? - 9/21/2005 3:00:37 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
what does the "0" do instead of the "1"


How can I implement this:

Dim wShell, oExec
Set wShell = CreateObject("WScript.Shell")

Set oExec = wShell.Exec("regedit /s p.reg")

Do While oExec.Status = 0
     WScript.Sleep 100
Loop


into my script so I don't have to see that CMD window?


Set network = WScript.CreateObject("WScript.Network")
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set WshShell = Wscript.CreateObject("Wscript.Shell")
fso.CopyFile "\\Prod2\N_Drive\Public\vptray.reg", "C:\"
WScript.Sleep 500
WshShell.run "regedit /S ""c:\vptray.reg""",0,True
WScript.Sleep 30000
fso.DeleteFile "c:\vptray.reg"


I tried it a bunch a ways and nothing.

(in reply to Country73)
 
 
Post #: 6
 
 RE: call a .reg file from VBS, how? - 9/21/2005 4:08:36 AM   
  sethsdad


Posts: 115
Score: 0
Joined: 4/4/2005
From: USA
Status: offline
O is a window style.  This wasn't easy to find, but here is the "bible" on the run command:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsmthrun.asp

(in reply to kracksmith)
 
 
Post #: 7
 
 RE: call a .reg file from VBS, how? - 9/21/2005 4:22:41 AM   
  Country73


Posts: 712
Score: 8
Joined: 8/25/2004
From: USA
Status: offline
Using WshShell.run, the setup is:

object.Run strCommand, intWindowStyle, bWaitOnReturn
 
"0" Hides the window
"1" Activates and displays a window
This line of code will hide the CMD window (0) and wait for it to complete before going on to the next step:
   WshShell.Run "regedit /S c:\vptray.reg",0,True

This will show the CMD window (1) and wait for it to complete before going on the the next step:
   WshShell.Run "regedit /S c:\vptray.reg",1,True

You can omit:
   Do While oExec.Status = 0
        WScript.Sleep 100
   Loop
Because the TRUE at the end of our line takes care of it.(bWaitOnReturn)
The only thing you will need to put in to run your reg file (without showing the cmd window) is:

   Set wShell = CreateObject("WScript.Shell")
   wShell.Run "regedit /S c:\vptray.reg",0,True
Then continue on with your code.
 
Actually, you can click on the link in my sig "Script56.chm" and you can download the Help File which makes it a lot easier to locate that sort of stuff.
(Same as what you would find from the link that Sethsdad posted but at your finger tips)

< Message edited by Country73 -- 9/21/2005 4:38:02 AM >

(in reply to kracksmith)
 
 
Post #: 8
 
 RE: call a .reg file from VBS, how? - 9/21/2005 5:01:14 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
ok Thanks for everyone's help. We are really making good progress here.


Here is my final working sript for this problem:


Set network = WScript.CreateObject("WScript.Network")
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set WshShell = Wscript.CreateObject("Wscript.Shell")
fso.CopyFile "\\Prod2\N_Drive\Public\vptray.reg", "C:\Documents and Settings\All Users\Desktop\"
WScript.Sleep 500
WshShell.run "regedit /S ""C:\Documents and Settings\All Users\Desktop\vptray.reg""",0,True
WScript.Sleep 30000
fso.DeleteFile "C:\Documents and Settings\All Users\Desktop\vptray.reg"



What's the purpose of the DIM? when i use the DIM it works and when I don't use it, it still works. If i don't use it, i don't need to set DIM to nothing at the end.

Also I wasn't able to copy things to the C:\ as most workstation we have here are power user with no rights to write to the C:\.  So I changed it to "C:\Documents and Settings\All Users\Desktop\"

I also stayed with "WshShell.run "regedit /S ""C:\Documents and Settings\All Users\Desktop\vptray.reg""",0,True"

instead of

"wShell.Run "regedit /S C:\Documents and Settings\All Users\Desktop\vptray.reg",2021,True" as 2021 didn't quite work out for me. Is it supposed to be commas before and after?

(in reply to Country73)
 
 
Post #: 9
 
 RE: call a .reg file from VBS, how? - 9/21/2005 5:08:09 AM   
  Country73


Posts: 712
Score: 8
Joined: 8/25/2004
From: USA
Status: offline
The 2021 was fat fingered and I guess I didn't get it corrected quickly enough.

The Dim is required whenever you use "Option Explicit" on your scripts.
If you don't use Option Explicit, then you don't need to use Dim.
If you downloaded the Script56.chm, or you can go out to the site that Sethsdad posted, you can look up Option Explicit for more information.

Also, you can probably get rid of the "Wscript.Sleep 30000" unless you're wanting a pause after the reg file has completed.

(in reply to kracksmith)
 
 
Post #: 10
 
 RE: call a .reg file from VBS, how? - 9/21/2005 5:15:45 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
Ok you got all my questions answered, thanks again. i will check out script56 right now for futher information.


(in reply to Country73)
 
 
Post #: 11
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> call a .reg file from VBS, how? Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts