Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Please help me debug this!
New Posts  All Forums:Forum Nav:

Please help me debug this!

post #1 of 9
Thread Starter 
I can't figure out why this script won't work...

No matter what happens, it proceeds as if the variable is 6.0 or 6.1.

Why??

Code:
Option Explicit
Dim objWMI, objItem, strNewName, RemotePath1, DriveLetter1, objShell, objNetwork, colItems, WshS, fso, filesys, objFSO, usrProfile, actualpath, networkpath
Dim strComputer, VerOS, VerBig, Ver9x, Version9x, OS, OSystem

strComputer = "."

' This is where WMI interrogates the operating system
Set objWMI = GetObject("winmgmts:\\\\" & strComputer & "\
oot\\cimv2")

Set colItems = objWMI.ExecQuery("Select * from Win32_OperatingSystem",,48)

' Here we filter Version from the dozens of properties
For Each objItem in colItems
VerBig = Left(objItem.Version,3)
Next

MsgBox VerBig

If VerBig = 6.0 or 6.1 Then

    Wscript.Echo "Now mounting for Vista/Windows 7"
    Set WshS = WScript.CreateObject("WScript.Shell")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set filesys = CreateObject("Scripting.FileSystemObject")
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    usrProfile = WshS.ExpandEnvironmentStrings("%UserProfile%")

    actualpath = Replace(usrProfile, "C:\\Users\\", "")

    networkpath = "\\\\ccs-is-svr01\\VirtualFlashDrive\\" & actualpath 

    If filesys.FolderExists (networkpath) Then
    elseif     objFSO.CreateFolder(networkpath) Then
            
    End If

    Set objNetwork = CreateObject("WScript.Network") 
    Set objShell = CreateObject("WScript.Shell") 
    DriveLetter1 = "V:"
    RemotePath1 = networkpath
    strNewName = "VirtualFlashDrive"

    objNetwork.MapNetworkDrive DriveLetter1, RemotePath1

    Set objShell = CreateObject("Shell.Application")
    objShell.NameSpace(DriveLetter1).Self.Name = strNewName
    
    
ElseIf VerBig = 5.1 Then

        Wscript.Echo "Now mounting for XP"
        Set WshS = WScript.CreateObject("WScript.Shell")
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set filesys = CreateObject("Scripting.FileSystemObject")

        usrProfile = WshS.ExpandEnvironmentStrings("%UserProfile%")

        actualpath = Replace(usrProfile, "C:\\Documents and Settings\\", "")

        networkpath = "\\\\ccs-is-svr01\\VirtualFlashDrive\\" & actualpath 

        If filesys.FolderExists (networkpath) Then
        elseif filesys.CreateFolder (networkpath) Then
        End If

        Set objNetwork = CreateObject("WScript.Network") 
        Set objShell = CreateObject("WScript.Shell") 
        DriveLetter1 = "V:"
        RemotePath1 = networkpath
        strNewName = "VirtualFlashDrive"

        objNetwork.MapNetworkDrive DriveLetter1, RemotePath1

        Set objShell = CreateObject("Shell.Application")
        objShell.NameSpace(DriveLetter1).Self.Name = strNewName
        
        
else 
    End If
WaterWorks
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Quad Q6700 (3.79GHz) ASUS Maximus Formula X38 PNY XLR8 GTX280 1024MB 6GB Dual Channel PC6400 5-4-4-12 (800MHz) 
Hard DriveOptical DriveOSMonitor
1.18TB RAID 0 + 500GB RAID 0 + 400GB Spare Lite-On Blu-Ray Drive Windows 7 Ultimate x64 I-INC 28" HDMI 1920x1200 
KeyboardPowerCaseMouse
Logitch G15 Corsair 900w Cooler Master Cosmos 1000 (Modded) Logitch G5 
Mouse Pad
Ergonomic Wrist Support 
  hide details  
Reply
WaterWorks
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Quad Q6700 (3.79GHz) ASUS Maximus Formula X38 PNY XLR8 GTX280 1024MB 6GB Dual Channel PC6400 5-4-4-12 (800MHz) 
Hard DriveOptical DriveOSMonitor
1.18TB RAID 0 + 500GB RAID 0 + 400GB Spare Lite-On Blu-Ray Drive Windows 7 Ultimate x64 I-INC 28" HDMI 1920x1200 
KeyboardPowerCaseMouse
Logitch G15 Corsair 900w Cooler Master Cosmos 1000 (Modded) Logitch G5 
Mouse Pad
Ergonomic Wrist Support 
  hide details  
Reply
post #2 of 9
I havent coded in forever, but isnt: If VerBig = 6.0 or 6.1 Then


supposed to be: If VerBig == 6.0 or 6.1 Then

Like when checking/reading a variable in an if statement aren't you supposed to use == because = actually sets the variable?
Monolith
(17 items)
 
  
CPUMotherboardGraphicsGraphics
3560K Asrock Z77 Extreme 4 GTX 670 GTX 260 Core 216 
RAMHard DriveHard DriveHard Drive
16 GB G. Skill Ram m4 SSD Hatachi HDDs 250GB W HDD 
Hard DriveOptical DriveOSMonitor
Western Digital HD LG BluRay Burner Windows 7 x64 Qnix 27" QX2700 
KeyboardPowerCaseMouse
Microsoft Sidewinder X4 Corsair HXW 750W NZXT Switch 810 Deathadder 
  hide details  
Reply
Monolith
(17 items)
 
  
CPUMotherboardGraphicsGraphics
3560K Asrock Z77 Extreme 4 GTX 670 GTX 260 Core 216 
RAMHard DriveHard DriveHard Drive
16 GB G. Skill Ram m4 SSD Hatachi HDDs 250GB W HDD 
Hard DriveOptical DriveOSMonitor
Western Digital HD LG BluRay Burner Windows 7 x64 Qnix 27" QX2700 
KeyboardPowerCaseMouse
Microsoft Sidewinder X4 Corsair HXW 750W NZXT Switch 810 Deathadder 
  hide details  
Reply
post #3 of 9
Not much time to look at this right now HOWEVER

In you evaluation statement to 6.0 or 6.1 you may have to put quotes around them to indicate it's a string. That or do a string compare.

Working in .NET these past few years my older VB/WScript is a bit rusty.

Let get the code and try a few things
Refreshed Duo
(13 items)
 
  
CPUMotherboardGraphicsRAM
E8500 E0@4.25Ghz (500x8.5) Gigabyte GA-EP45-UD3P EVGA GTX285 (720/1674/2772) 2x2gb G.SKILL PC8500 
Hard DriveOptical DriveOSMonitor
3xWD 250GB RAID0 Sony DVD/CDR/RW Windows 7 Ultimate x64 ACER 24" P241WAID LCD 
KeyboardPowerCaseMouse
Logitech G15 (Original) OCZ GameXStream 700w SLI ThermalTake Armor Black Logitech G5 
Mouse Pad
Razor XACT 
  hide details  
Reply
Refreshed Duo
(13 items)
 
  
CPUMotherboardGraphicsRAM
E8500 E0@4.25Ghz (500x8.5) Gigabyte GA-EP45-UD3P EVGA GTX285 (720/1674/2772) 2x2gb G.SKILL PC8500 
Hard DriveOptical DriveOSMonitor
3xWD 250GB RAID0 Sony DVD/CDR/RW Windows 7 Ultimate x64 ACER 24" P241WAID LCD 
KeyboardPowerCaseMouse
Logitech G15 (Original) OCZ GameXStream 700w SLI ThermalTake Armor Black Logitech G5 
Mouse Pad
Razor XACT 
  hide details  
Reply
post #4 of 9
Found your problem.. Had to look at it again..

It's your IF statement

Code:
Option Explicit
Dim VerBig

VerBig = "6.1"

If VerBig = "6.0" or VerBig = "6.1" Then

    Wscript.Echo "Now mounting for Vista/Windows 7"  
    
ElseIf VerBig = "5.1" Then

    Wscript.Echo "Now mounting for WinXP" 
              
End If
To test it I just set the VerBig value to 6.0, 6.1 and 5.1 and each time the 2 triggered the Vista confirm and now on 5.1 it shows the XP...

Also NO NEED for the Else/EndIf at the end.. Just the EndIF will suffice

Here is your code with the changes and I also changed 2 of the If statements to do a IF NOT instead of your If (statement=true) elseif.. I've bolded them as well and should work, if not go back to your first iteration.

Code:
Option Explicit
Dim objWMI, objItem, strNewName, RemotePath1, DriveLetter1, objShell, objNetwork, colItems, WshS, fso, filesys, objFSO, usrProfile, actualpath, networkpath
Dim strComputer, VerOS, VerBig, Ver9x, Version9x, OS, OSystem

strComputer = "."

' This is where WMI interrogates the operating system
Set objWMI = GetObject("winmgmts:\\" & strComputer & "rootcimv2")

Set colItems = objWMI.ExecQuery("Select * from Win32_OperatingSystem",,48)

' Here we filter Version from the dozens of properties
For Each objItem in colItems
  VerBig = Left(objItem.Version,3)
Next

MsgBox VerBig

If VerBig = "6.0" or VerBig = "6.1" Then

    Wscript.Echo "Now mounting for Vista/Windows 7"
    Set WshS = WScript.CreateObject("WScript.Shell")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set filesys = CreateObject("Scripting.FileSystemObject")
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    usrProfile = WshS.ExpandEnvironmentStrings("%UserProfile%")

    actualpath = Replace(usrProfile, "C:Users\\", "")

    networkpath = "\\ccs-is-svr01VirtualFlashDrive\\" & actualpath 

    If not filesys.FolderExists (networkpath) Then objFSO.CreateFolder(networkpath)

    Set objNetwork = CreateObject("WScript.Network") 
    Set objShell = CreateObject("WScript.Shell") 
    DriveLetter1 = "V:"
    RemotePath1 = networkpath
    strNewName = "VirtualFlashDrive"

    objNetwork.MapNetworkDrive DriveLetter1, RemotePath1

    Set objShell = CreateObject("Shell.Application")
    objShell.NameSpace(DriveLetter1).Self.Name = strNewName
    
    
ElseIf VerBig = "5.1" Then

        Wscript.Echo "Now mounting for XP"
        Set WshS = WScript.CreateObject("WScript.Shell")
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set filesys = CreateObject("Scripting.FileSystemObject")

        usrProfile = WshS.ExpandEnvironmentStrings("%UserProfile%")

        actualpath = Replace(usrProfile, "C:Documents and Settings\\", "")

        networkpath = "\\ccs-is-svr01VirtualFlashDrive\\" & actualpath 

        If not filesys.FolderExists (networkpath) Then filesys.CreateFolder (networkpath)

        Set objNetwork = CreateObject("WScript.Network") 
        Set objShell = CreateObject("WScript.Shell") 
        DriveLetter1 = "V:"
        RemotePath1 = networkpath
        strNewName = "VirtualFlashDrive"

        objNetwork.MapNetworkDrive DriveLetter1, RemotePath1

        Set objShell = CreateObject("Shell.Application")
        objShell.NameSpace(DriveLetter1).Self.Name = strNewName
End If

Edited by Ictinike - 12/12/08 at 11:28am
Refreshed Duo
(13 items)
 
  
CPUMotherboardGraphicsRAM
E8500 E0@4.25Ghz (500x8.5) Gigabyte GA-EP45-UD3P EVGA GTX285 (720/1674/2772) 2x2gb G.SKILL PC8500 
Hard DriveOptical DriveOSMonitor
3xWD 250GB RAID0 Sony DVD/CDR/RW Windows 7 Ultimate x64 ACER 24" P241WAID LCD 
KeyboardPowerCaseMouse
Logitech G15 (Original) OCZ GameXStream 700w SLI ThermalTake Armor Black Logitech G5 
Mouse Pad
Razor XACT 
  hide details  
Reply
Refreshed Duo
(13 items)
 
  
CPUMotherboardGraphicsRAM
E8500 E0@4.25Ghz (500x8.5) Gigabyte GA-EP45-UD3P EVGA GTX285 (720/1674/2772) 2x2gb G.SKILL PC8500 
Hard DriveOptical DriveOSMonitor
3xWD 250GB RAID0 Sony DVD/CDR/RW Windows 7 Ultimate x64 ACER 24" P241WAID LCD 
KeyboardPowerCaseMouse
Logitech G15 (Original) OCZ GameXStream 700w SLI ThermalTake Armor Black Logitech G5 
Mouse Pad
Razor XACT 
  hide details  
Reply
post #5 of 9
Thread Starter 
Wow thanks so much! I've had zero training or learning in VBS, I'm just winging it all...

Reps+
WaterWorks
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Quad Q6700 (3.79GHz) ASUS Maximus Formula X38 PNY XLR8 GTX280 1024MB 6GB Dual Channel PC6400 5-4-4-12 (800MHz) 
Hard DriveOptical DriveOSMonitor
1.18TB RAID 0 + 500GB RAID 0 + 400GB Spare Lite-On Blu-Ray Drive Windows 7 Ultimate x64 I-INC 28" HDMI 1920x1200 
KeyboardPowerCaseMouse
Logitch G15 Corsair 900w Cooler Master Cosmos 1000 (Modded) Logitch G5 
Mouse Pad
Ergonomic Wrist Support 
  hide details  
Reply
WaterWorks
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Quad Q6700 (3.79GHz) ASUS Maximus Formula X38 PNY XLR8 GTX280 1024MB 6GB Dual Channel PC6400 5-4-4-12 (800MHz) 
Hard DriveOptical DriveOSMonitor
1.18TB RAID 0 + 500GB RAID 0 + 400GB Spare Lite-On Blu-Ray Drive Windows 7 Ultimate x64 I-INC 28" HDMI 1920x1200 
KeyboardPowerCaseMouse
Logitch G15 Corsair 900w Cooler Master Cosmos 1000 (Modded) Logitch G5 
Mouse Pad
Ergonomic Wrist Support 
  hide details  
Reply
post #6 of 9
Thread Starter 
I finally recreated the script, and now I get a (null): IDispatch error #3617...

Ideas?
WaterWorks
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Quad Q6700 (3.79GHz) ASUS Maximus Formula X38 PNY XLR8 GTX280 1024MB 6GB Dual Channel PC6400 5-4-4-12 (800MHz) 
Hard DriveOptical DriveOSMonitor
1.18TB RAID 0 + 500GB RAID 0 + 400GB Spare Lite-On Blu-Ray Drive Windows 7 Ultimate x64 I-INC 28" HDMI 1920x1200 
KeyboardPowerCaseMouse
Logitch G15 Corsair 900w Cooler Master Cosmos 1000 (Modded) Logitch G5 
Mouse Pad
Ergonomic Wrist Support 
  hide details  
Reply
WaterWorks
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Quad Q6700 (3.79GHz) ASUS Maximus Formula X38 PNY XLR8 GTX280 1024MB 6GB Dual Channel PC6400 5-4-4-12 (800MHz) 
Hard DriveOptical DriveOSMonitor
1.18TB RAID 0 + 500GB RAID 0 + 400GB Spare Lite-On Blu-Ray Drive Windows 7 Ultimate x64 I-INC 28" HDMI 1920x1200 
KeyboardPowerCaseMouse
Logitch G15 Corsair 900w Cooler Master Cosmos 1000 (Modded) Logitch G5 
Mouse Pad
Ergonomic Wrist Support 
  hide details  
Reply
post #7 of 9
Thread Starter 
Ok I've got it running now. However, Vista and Windows 7 will NOT mount the drive if UAC is enabled. I'm guessing this is due to our server being Server 2003.

Any ideas how to put a line in about authenticating to UAC?
WaterWorks
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Quad Q6700 (3.79GHz) ASUS Maximus Formula X38 PNY XLR8 GTX280 1024MB 6GB Dual Channel PC6400 5-4-4-12 (800MHz) 
Hard DriveOptical DriveOSMonitor
1.18TB RAID 0 + 500GB RAID 0 + 400GB Spare Lite-On Blu-Ray Drive Windows 7 Ultimate x64 I-INC 28" HDMI 1920x1200 
KeyboardPowerCaseMouse
Logitch G15 Corsair 900w Cooler Master Cosmos 1000 (Modded) Logitch G5 
Mouse Pad
Ergonomic Wrist Support 
  hide details  
Reply
WaterWorks
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Quad Q6700 (3.79GHz) ASUS Maximus Formula X38 PNY XLR8 GTX280 1024MB 6GB Dual Channel PC6400 5-4-4-12 (800MHz) 
Hard DriveOptical DriveOSMonitor
1.18TB RAID 0 + 500GB RAID 0 + 400GB Spare Lite-On Blu-Ray Drive Windows 7 Ultimate x64 I-INC 28" HDMI 1920x1200 
KeyboardPowerCaseMouse
Logitch G15 Corsair 900w Cooler Master Cosmos 1000 (Modded) Logitch G5 
Mouse Pad
Ergonomic Wrist Support 
  hide details  
Reply
post #8 of 9
Why don't you just disable UAC? lots of problems solved that way

You can run a batch shell command to disable UAC, so just include that in your batch file. And if you really want it on, disable it in the batch file, then do your normal code, then do a re-enable UAC.

BloodfireLAN
(16 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500K Asus P67 Pro Asus GTX 680 32GB G. Skill 
Hard DriveHard DriveOptical DriveOS
1TB SATA6 WD Caviar Black Corsair 240GB N/A Win 8 Pro x64 
MonitorMonitorMonitorKeyboard
Asus P278Q 1440p BenQ 1080p BenQ 1080p maxxkeyboard Custom Mechanical MX Cherry Brown 
PowerCaseMouseMouse Pad
Corsair 750TX Custom build in the works Logitech Trackball/Logitech Anywhere Mouse MX N/A 
  hide details  
Reply
BloodfireLAN
(16 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500K Asus P67 Pro Asus GTX 680 32GB G. Skill 
Hard DriveHard DriveOptical DriveOS
1TB SATA6 WD Caviar Black Corsair 240GB N/A Win 8 Pro x64 
MonitorMonitorMonitorKeyboard
Asus P278Q 1440p BenQ 1080p BenQ 1080p maxxkeyboard Custom Mechanical MX Cherry Brown 
PowerCaseMouseMouse Pad
Corsair 750TX Custom build in the works Logitech Trackball/Logitech Anywhere Mouse MX N/A 
  hide details  
Reply
post #9 of 9
Thread Starter 
Quote:
Originally Posted by Bloodfire View Post
Why don't you just disable UAC? lots of problems solved that way

You can run a batch shell command to disable UAC, so just include that in your batch file. And if you really want it on, disable it in the batch file, then do your normal code, then do a re-enable UAC.

Yeahhh no. This is for a school, and I WANT UAC enabled. Also, it's not feasible to go around to 100 computers and disable UAC. I'd like to do what you're SUPPOSED to do, and Authenticate.
WaterWorks
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Quad Q6700 (3.79GHz) ASUS Maximus Formula X38 PNY XLR8 GTX280 1024MB 6GB Dual Channel PC6400 5-4-4-12 (800MHz) 
Hard DriveOptical DriveOSMonitor
1.18TB RAID 0 + 500GB RAID 0 + 400GB Spare Lite-On Blu-Ray Drive Windows 7 Ultimate x64 I-INC 28" HDMI 1920x1200 
KeyboardPowerCaseMouse
Logitch G15 Corsair 900w Cooler Master Cosmos 1000 (Modded) Logitch G5 
Mouse Pad
Ergonomic Wrist Support 
  hide details  
Reply
WaterWorks
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Quad Q6700 (3.79GHz) ASUS Maximus Formula X38 PNY XLR8 GTX280 1024MB 6GB Dual Channel PC6400 5-4-4-12 (800MHz) 
Hard DriveOptical DriveOSMonitor
1.18TB RAID 0 + 500GB RAID 0 + 400GB Spare Lite-On Blu-Ray Drive Windows 7 Ultimate x64 I-INC 28" HDMI 1920x1200 
KeyboardPowerCaseMouse
Logitch G15 Corsair 900w Cooler Master Cosmos 1000 (Modded) Logitch G5 
Mouse Pad
Ergonomic Wrist Support 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Please help me debug this!