Scripts Thread, Help a newbie to VBscript in Coding and Web Development; I am trying to teach myself to use VBScript. I have managed to get almost everything working on this script. ...
-
20th May 2010, 10:47 AM #1 Help a newbie to VBscript
I am trying to teach myself to use VBScript. I have managed to get almost everything working on this script. However I can't get the last part to delete a reg key to keep our local profile start menu's in alphabetical order. It works in my batch files but not the VBscript.
Can any one point where I am going wrong.
Script below
Option Explicit
Dim objNetwork, strRemotePath1, strRemotePath2
Dim strDriveLetter1, StrDriveLetter2
Dim Command, prntchar, backgr
Dim RegMenu, WshShell
'-------------------------------------------------------
'This section removes and reconnects the network drives
strDriveLetter1 = "M:"
strDriveLetter2 = "P:"
StrRemotePath1 = "\\server\sme"
StrRemotePath2 = "\\server-1\public"
Set objNetwork = CreateObject("WScript.Network")
'Section which removes Mapped Drive
objNetwork.RemoveNetworkDrive strDriveLetter1, strRemotePath1
objNetwork.RemoveNetworkDrive strDriveLetter2, strRemotePath2
'Section which connects Mapped Drive
objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2
'---------------------------------------------------------
'Printing Section
'---------------------------------------------------------
'Creation of custom desktop background using BGInfo
Set Command = WScript.CreateObject("WScript.Shell")
backgr = "c:\windows\bginfo\bginfo.exe /i""c:\windows\bginfo\students.bgi"" /accepteula /timer:0"
Command.Run (backgr)
'---------------------------------------------------------
'Start Ranger Print Client software
Set Command = WScript.CreateObject("WScript.Shell")
prntchar = "\\server\rangerprint\gpclient.exe data=\\server\rangerprint\data"
Command.run (prntchar)
'---------------------------------------------------------
'Remove registry key to keep startmenu alphabetised
RegMenu = "HKEY_CURRENT_USER\Software\Microsoft\Windows\Curr entVersion\Explorer\MenuOrder"" /f"
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegDelete Regmenu
Set WshShell = Nothing
'---------------------------------------------------------
WScript.Quit
Ta for any help.
-
-
IDG Tech News
-
20th May 2010, 11:17 AM #2 
Originally Posted by
denon101
'---------------------------------------------------------
'Remove registry key to keep startmenu alphabetised
RegMenu = "HKEY_CURRENT_USER\Software\Microsoft\Windows\Curr entVersion\Explorer\MenuOrder"" /f"
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegDelete Regmenu
Set WshShell = Nothing
'---------------------------------------------------------
WScript.Quit
Maybe try removing the extra spaces between curr entversion and also the " /f" from the end - as far as i know it is just the key that is required no switches
regards
Mark
-
-
20th May 2010, 11:20 AM #3 Where did you get the code from?
i'm not too hot on scripting, but have done some. i'm not sure why you have that "/f" in there.
syntax matters a lot, as does the version of Windows you are on.
but the main issue is if the key has subkeys, which causes a problem.
perhaps you could use a bat file and call it from the vbscript, possibly even easier write a .reg file that deletes the key, i think that's possible (?) and execute that from the vbscript.
see link for help on deleting with vbscript
Hey, Scripting Guy!: How Can I Delete a Key and its Subkeys from the Registry?
-
-
20th May 2010, 11:22 AM #4 good catch mark, i assumed the space was due to wordwrap!
-
-
20th May 2010, 11:34 AM #5 @vikpaw's suggestion of using the Scripting Guys code is good - just replace the whole of your "'Remove registry key to keep startmenu alphabetised" section with their code to delete a tree and change the key path to this:
Code:
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder"
Another alternative would be to replace the block with:
Code:
sCmd="reg delete ""HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder"" /f"
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.run sCmd (and I'd guess the OP has done what we all do - found 2 bits of code which almost do what's needed and mix them together but not got it quite right - you can use the shell object to do a "regdelete" but the syntax is slightly different or you can just shell out and run the "reg" command which is what this does)
-
-
20th May 2010, 11:54 AM #6 Download a copy of VbsEdit - it's got code snippets for all sorts of stuff, including what you want to do. It's an evaluation version that never runs out - just has some nag screens. Or there's this site: Registry Scripting Center - the scripts are similar to VbsEdit's snippets.
-
-
20th May 2010, 11:59 AM #7 Well the code has come from example scripts off the web and as you guys suggest is more than likely wrong. Shall give your ideas a bash and plod on. Will no doubt be back at some point!!
Thanks
Oh and on the code I input there are no spaces between the current version code. Must be the wrod wrap as suggested.
-
-
22nd May 2010, 12:23 PM #8 
Originally Posted by
Gerry
Download a copy of
VbsEdit - it's got code snippets for all sorts of stuff, including what you want to do. It's an evaluation version that never runs out - just has some nag screens. Or there's this site:
Registry Scripting Center - the scripts are similar to VbsEdit's snippets.
I tried vbsedit : it's okay, but really annoying, everytime i want to do a debug run, it starts a timer, that started at 3 seconds and goes up by a second every time i run again. i'm up to 10 seconds. i think the advantage of snippets is being cancelled out by the annoyance factor!
-
SHARE:
Similar Threads
-
Replies: 5
Last Post: 15th March 2010, 04:04 PM
-
By Sirbendy in forum Scripts
Replies: 0
Last Post: 6th October 2008, 01:24 PM
-
By soze in forum How do you do....it?
Replies: 2
Last Post: 2nd June 2008, 05:44 PM
-
By StewartKnight in forum Coding
Replies: 5
Last Post: 1st May 2007, 11:04 AM
-
By mac_shinobi in forum Scripts
Replies: 1
Last Post: 14th September 2005, 08:21 AM
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules