+ Post New Thread
Results 1 to 8 of 8
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. ...
  1. #1
    denon101's Avatar
    Join Date
    Jul 2008
    Location
    Stuck in the server room......
    Posts
    395
    Thank Post
    54
    Thanked 37 Times in 35 Posts
    Rep Power
    21

    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.

  2. #2
    sister_annex's Avatar
    Join Date
    Jan 2009
    Location
    Wolverhampton
    Posts
    594
    Thank Post
    100
    Thanked 136 Times in 120 Posts
    Rep Power
    49
    Quote Originally Posted by denon101 View Post
    '---------------------------------------------------------

    '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

  3. #3

    vikpaw's Avatar
    Join Date
    Sep 2006
    Location
    Saudi Arabia
    Posts
    5,639
    Thank Post
    683
    Thanked 1,400 Times in 1,160 Posts
    Rep Power
    353
    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?

  4. #4

    vikpaw's Avatar
    Join Date
    Sep 2006
    Location
    Saudi Arabia
    Posts
    5,639
    Thank Post
    683
    Thanked 1,400 Times in 1,160 Posts
    Rep Power
    353
    good catch mark, i assumed the space was due to wordwrap!

  5. #5

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,157
    Thank Post
    116
    Thanked 529 Times in 452 Posts
    Blog Entries
    2
    Rep Power
    124
    @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)

  6. #6
    Gerry's Avatar
    Join Date
    Jun 2007
    Location
    North Wales
    Posts
    431
    Thank Post
    60
    Thanked 38 Times in 35 Posts
    Rep Power
    24
    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.

  7. #7
    denon101's Avatar
    Join Date
    Jul 2008
    Location
    Stuck in the server room......
    Posts
    395
    Thank Post
    54
    Thanked 37 Times in 35 Posts
    Rep Power
    21
    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.

  8. #8

    vikpaw's Avatar
    Join Date
    Sep 2006
    Location
    Saudi Arabia
    Posts
    5,639
    Thank Post
    683
    Thanked 1,400 Times in 1,160 Posts
    Rep Power
    353
    Quote Originally Posted by Gerry View Post
    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:
+ Post New Thread

Similar Threads

  1. Teach Yourself VBScript
    By Rawns in forum Coding
    Replies: 5
    Last Post: 15th March 2010, 03:04 PM
  2. VBScript help.
    By Sirbendy in forum Scripts
    Replies: 0
    Last Post: 6th October 2008, 01:24 PM
  3. VBSCRIPT
    By soze in forum How do you do....it?
    Replies: 2
    Last Post: 2nd June 2008, 05:44 PM
  4. VBScript
    By StewartKnight in forum Coding
    Replies: 5
    Last Post: 1st May 2007, 11:04 AM
  5. Printer vbscript ?
    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
  •