Scripts Thread, Sub within a sub - VBS Script in Coding and Web Development; Hi
What I am doing is re-doing the sartup script to work with vista as well.
This is a snipit ...
-
17th May 2008, 05:24 PM #1
Sub within a sub - VBS Script
Hi
What I am doing is re-doing the sartup script to work with vista as well.
This is a snipit of my code:
Code:
If filesys.FileExists ("C:\WINDOWS\Web\Wallpaper\Windows XP.jpg") Then call xp2003
If filesys.FileExists ("C:\WINDOWS\Web\Wallpaper\Windows Server 2003.bmp") Then call xp2003
If filesys.FileExists ("C:\Users\Default\ntuser.dat.log") Then call nt6
‘******Windows XP & 2003******
sub xp2003
If Not fso.FileExists("C:\Documents and Settings\All Users\Start Menu\Programs\Kar2ouche\kar2ouche.lnk") Then
call kar2ouche
End If
sub kar2ouche
filesys.CreateFolder "C:\Documents and Settings\All Users\Start Menu\Programs\Kar2ouche"
filesys.CopyFile "\\server\NETLOGON\shortcuts\Kar2ouche.lnk", "c:\Documents and Settings\All Users\Start Menu\Programs\Kar2ouche\"
END sub
fso.DeleteFile("C:\documents and settings\all users\desktop\Microsoft Student with Encarta Premium 2008 DVD.lnk")
END sub
‘******Windows Vista & 2008******
Sub nt6
END sub Basically I have a sub within a sub and it doesn’t work. I want to keep the start-up scrip al in one and not have separate ones for Vista & XP. How do I go about this please?
Please Note: There will be some code in the Vista section but i haven't done it yet.
-
-
IDG Tech News
-
17th May 2008, 06:02 PM #2 Your subroutine should be defined outside the other subroutine just like the first one, you should then call the subroutine if needed from within your subroutine. If the subroutine is not called it is not executed and so should not slow the execution down.
If you are doing this to clean up the code and make it more readable you could put all of your subroutines in an include file like this
Basically you chuck all of your subroutines in the VBS file and then run the WSF that includes the VBS, much cleaner and it only need WSH 2.0 (in Windows 2000) or higher to run them.
-
-
17th May 2008, 06:07 PM #3 Do you mean the XP section?
Im not doing it to clean it up just dont want Vista running the XP code and vise versa.
-
-
17th May 2008, 06:23 PM #4 I mean that all of the subroutines should be flat and not nested inside one another like this:
Code:
Sub DoOneThing
MSGbox "One Thing"
if bla then DoAnotherThingForXP
End Sub
Sub DoAnotherThingForXP
EndSub
Sub DoAnotherThingForVista
EndSub
As long as the code does not call the routine they will not be run so if your logic says if XP then do this bunch of stuff defined in these subroutines it will only run those subroutines that are called from your main block of code.
Basically if I define a subroutine and do not call it in a script it will not run that chunk of code.
-
-
18th May 2008, 06:18 PM #5 On a slightly different note, if you want to determine the version of Windows, it's probably better to use WMI rather than checking for files which might not be there (particularly bitmaps which might get deleted when you decide to try and tidy up the image ...)
The function below will give you back the version number of Windows - eg 5.1.2600 for XP; 5.2.3790 for Server 2003.
Code:
function GetOS
Set oWMI = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = oWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48)
For Each oItem in colItems
GetOS=oItem.Version
Next
end function
-
-
18th May 2008, 06:30 PM #6 Win32 class for wmi
if you look here :
Win32_OperatingSystem Class (Windows)
you can use the caption property in that code possibly and that should tell you the version as well as a string of what os it is.
Code:
function GetOS
Set oWMI = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = oWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48)
For Each oItem in colItems
GetOS=oItem.Caption '<-- changed it here
Next
end function
-
SHARE: 
Similar Threads
-
By bizzel in forum Scripts
Replies: 6
Last Post: 9th March 2008, 12:15 AM
-
By salan in forum Windows
Replies: 8
Last Post: 8th November 2007, 06:55 PM
-
Replies: 0
Last Post: 6th November 2007, 11:48 PM
-
By Galway in forum Windows
Replies: 3
Last Post: 29th August 2007, 11:00 AM
-
By wesleyw in forum Scripts
Replies: 4
Last Post: 5th July 2007, 01:58 PM
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