Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Recommended Posts

Posted

Hi

What I am doing is re-doing the sartup script to work with vista as well.

 

This is a snipit of my 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.

Posted

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.

Posted
just like the first one

 

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.

Posted

I mean that all of the subroutines should be flat and not nested inside one another like this:

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.

Posted

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.

 

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

Posted

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.

 


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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...