Halfmad Posted October 31, 2007 Report Posted October 31, 2007 Hi all, Not entirely sure this is possible but essentially what I'd like to do is have my login script pick one of 5 lines and execute it. My idea was using a command to pick a random number (1-5) then calling in one of five external batch files (named batch1.bat, batch2.bat etc) and running it. Possible? It's just a bit of fun to randomise pupil desktops with BGInfo
mattx Posted October 31, 2007 Report Posted October 31, 2007 You will have to try and fiddle around with the %Random% global variable - I am sure something could be done - I did a random 6 letter thing in AutoIT. You are welcome to edit and mess around with it to suit your requirements: ; AutoIt Version: 3.00 ; Language: English ; Platform: WinXP ; Author: Matt ; Script Function: Random Letters Generator For Possible Password Use $__msgbox = MsgBox(4, 'Random Letter Generator By Matt', 'This Will Generate 6 Random Letters For You, Continue?') if ($__msgbox = 7) Then Exit EndIf SplashTextOn("Random Letter Generator By Matt", "Thinking Of 6 Letters, Please Wait...", 300, 75) Sleep(3000) Dim $i = 0, $word = "" For $i = 1 To 6 If Random() < 0.5 Then $Letter = Chr(Random(Asc("A"), Asc("Z"))) Else $Letter = Chr(Random(Asc("a"), Asc("z"))) EndIf $word = $word & $Letter Next Splashoff() Msgbox(64, "Your Random Letters Are:", $word)
mattx Posted October 31, 2007 Report Posted October 31, 2007 Just checking, a certain Rob van der Woude [ I must E-mail and thank him one day for his excellent website I have been using for years ] has done something which may help. Check out: http://www.robvanderwoude.com/batexamples_r.html#R
Halfmad Posted October 31, 2007 Author Report Posted October 31, 2007 Cheers Matt, looks good! *bookmarks site*
Halfmad Posted October 31, 2007 Author Report Posted October 31, 2007 Hi chaps here's what I hacked together from the link Matt gave me, just tested it and it appears to work. -------------------------------------- @ECHO OFF ECHO. IF NOT [%1]==[] GOTO Syntax VER | FIND "Windows 2000" >NUL IF NOT ERRORLEVEL 1 GOTO Start VER | FIND "Windows XP" >NUL IF NOT ERRORLEVEL 1 GOTO Start :Start SET NAT=%Random% IF [%NAT%]==[] GOTO Syntax IF %NAT% GTR 5 SET /A NAT = 1%NAT:~-1% -10 rem SET NAT IF '%NAT%'=='0' GOTO Nat0 IF '%NAT%'=='1' GOTO Nat1 IF '%NAT%'=='2' GOTO Nat0 IF '%NAT%'=='3' GOTO Nat1 IF '%NAT%'=='4' GOTO Nat0 IF '%NAT%'=='5' GOTO Nat1 IF '%NAT%'=='6' GOTO Nat0 IF '%NAT%'=='7' GOTO Nat1 IF '%NAT%'=='8' GOTO Nat0 IF '%NAT%'=='9' GOTO Nat1 Else goto Nat0 goto end :Nat0 "\\staff\NETLOGON\wallpapers\bginfo.exe" "\\staff\NETLOGON\wallpapers\Startup.bgi" /timer:0 GOTO End :Nat1 "\\staff\NETLOGON\wallpapers\bginfo.exe" "\\staff\NETLOGON\wallpapers\Startup2.bgi" /timer:0 GOTO End :End --------------------------------- Obviously you could have it randomising up to 10 different BGinfo setups but at the moment I only have two and have gotten side tracked as always! If I'm right the "else goto nat 0" shouldn't be needed as it can only produce results from 0-9, but I've been wrong before!
mattx Posted October 31, 2007 Report Posted October 31, 2007 God, I miss using GOTO commands.......... :-)
Halfmad Posted October 31, 2007 Author Report Posted October 31, 2007 yeah I should stop using the login batch files but you can have so much fun with them mate
Iain Posted October 31, 2007 Report Posted October 31, 2007 A possible vbscript solution could be: random.vbs: Dim objShell, intOption Set objShell = CreateObject("WScript.Shell") Randomize() intOption = Int(5*Rnd()) Select Case intOption Case 0 ' Option 1 objShell.Run "batch1.bat" Case 1 ' Option 2 objShell.Run "batch2.bat" Case 2 ' Option 3 objShell.Run "batch3.bat" Case 3 ' Option 4 objShell.Run "batch4.bat" Case 4 ' Option 5 objShell.Run "batch5.bat" End Select Set objShell = Nothing Iain
mattx Posted October 31, 2007 Report Posted October 31, 2007 I wonder how many of us have written Lottery Number Generators ? Last count I had done 3 - sad :downtown:
Friez Posted October 31, 2007 Report Posted October 31, 2007 In PHP: $num = array(); for($i=1;$i<=49;$i++) { array_push($num,$i); } shuffle($num); echo "Sad Little Lottery Generator for mattx "; for($i=0;$i<6;$i++) { echo $num[$i] . " "; } echo " Powered By Geekiness(tm)"; ?> Victory is mine!
Halfmad Posted October 31, 2007 Author Report Posted October 31, 2007 I knew someone was going to do that!
Friez Posted October 31, 2007 Report Posted October 31, 2007 I knew someone was going to do that! It had to be done TBH!
Zabu Posted November 6, 2007 Report Posted November 6, 2007 Here is a pretty flexible solution for running random files. It looks through a specified folder and picks a file at random out of the list of files in that folder. That way it works if you have 1 file in the folder or 100. dim arrImages(5000) strSourceFolder = "c:\FolderWithBatchFiles" Set objFSO = CreateObject("Scripting.FileSystemObject") Set objWshShell = WScript.CreateObject("WScript.Shell") 'Get a list of all of the files in the folder set objFolder = objFSO.GetFolder(strSourceFolder) Set colBatchFolder = objFolder.Files For Each objBatchFile in colBatchFolder arrBatchFiles(i) = objBatchFile.Name i=i+1 Next ' Create a random number from 0 to i Randomize intRandomNumber = Int(rnd* i) 'Run that puppy WshShell.Run arrBatchFiles(intRandomNumber) A good check would be to look at the file extension before tossing it into the array to make sure that it was a .bat file. I originally made it to look through my pictures and toss a random one into the registry as my wallpaper, but ran into problems with XP not refreshing it. Because I converted it, the variable names are probably a little wonky. Another way would be a modification of what was posted above. Generate a random number from 1 to 5 and then use a case statement. Rather than going to an external file the case statement would call 1 of 5 subroutines that would run the part of the logon script that provides individualization. If needed, any common elements can be meted out to users either before or after that part runs. Have a great day.
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