denon101 Posted May 20, 2010 Posted May 20, 2010 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\CurrentVersion\Explorer\MenuOrder"" /f" Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.RegDelete Regmenu Set WshShell = Nothing '--------------------------------------------------------- WScript.Quit Ta for any help.
sister_annex Posted May 20, 2010 Posted May 20, 2010 '--------------------------------------------------------- 'Remove registry key to keep startmenu alphabetised RegMenu = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\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
vikpaw Posted May 20, 2010 Posted May 20, 2010 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?
vikpaw Posted May 20, 2010 Posted May 20, 2010 good catch mark, i assumed the space was due to wordwrap!
srochford Posted May 20, 2010 Posted May 20, 2010 @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: strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder" Another alternative would be to replace the block with: 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)
Gerry Posted May 20, 2010 Posted May 20, 2010 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.
denon101 Posted May 20, 2010 Author Posted May 20, 2010 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.
vikpaw Posted May 22, 2010 Posted May 22, 2010 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!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now