WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Start Menu - TaskBar

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Autostart manager


Posted: 06/24/98

Note:Use this script at your own risk....
This is un-tested code written by one of our users and
posted to the WebBoard "WinBatch script exchange" conference.

AutoStrM.WBT

The Autostart manager should be compiled & a shortcut should be placed in the "Startup" group. Once run, it will create a new Start menu group, "Startup2" and more all Startup folder items there (except itself). From now on, upon request, it will show you a list of all Startup shortcuts and ask you which one to execute. Will run "as-is" under NT 4.0 only, but should be easy to modify to run under Win95 as well. I found this program handy since I did not want to have all Startup shortcuts executed at every logon.

Author: Michael Meron. Public domain. All inquiries to MMeron@csi.com. Enjoy!

; Initialization.
sTitle="Startup Manager"
sMyName=Winname()
sCallExtn="WBT" ; Extension of called files
If StrUpper(StrSub(sMyName,StrLen(sMyName)-2,3))=="EXE" Then sCallExtn="WBC"
bKeyIsOpen=@FALSE          ; No Reg key yet open.

; Temporarily turn errors off
nPrevErrMode=ErrorMode(@OFF)

; Get directory for current user profile
sUsrPrf=Environment("UserProfile")
If StrLen(sUsrPrf)==0
   Message("%sTitle% Error","Cannot find name of current user profile.")
   Goto EXIT
Endif

; Get folder name of Startup "Group"
; (must be done or won't run on international PCs).
sRootKeyName="Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
LastError()
hndKey=RegOpenKey(@REGCURRENT,sRootKeyName)
bKeyIsOpen=(LastError()==0)
If !bKeyIsOpen
   Message("%sTitle% Error","Cannot open registry key %sRootKeyName%.")
   Goto EXIT
Endif
sStartupDir=RegQueryExpSz(hndKey,"[Startup]")
If bKeyIsOpen
   RegCloseKey(hndKey)
   bKeyIsOpen=@FALSE
Endif

; Get full name of dir by replacing %USERPROFILE% with actual dir
If StrIndex(sStartupDir,"%%USERPROFILE%%",1,@FWDSCAN)>0
   sStartupDir=StrReplace(sStartupDir,"%%USERPROFILE%%",sUsrPrf)
Endif

; Create a Startup2 sub-folder if necessary. Abort immed on problems.
sStartup2Dir=StrCat(FilePath(sStartupDir),"\Startup2")
If DirExist(sStartup2Dir)==@FALSE
   LastError()
   DirMake(sStartup2Dir)
   If LastError()>0
      Message("%sTitle% Error","Could not create folder %sStartup2Dir%.")
      Goto EXIT
   Endif
Endif

; Move all files (except ourselves) from Startup to Startup2.
slStartupFiles=FileItemize("%sStartupDir%\*.*")
For n = 1 To ItemCount(slStartupFiles,@TAB)
   sFile=ItemExtract(n,slStartupFiles,@TAB)
   If StrSub(StrUpper(FileRoot(sFile)),1,4)!="AUTO"
      LastError()
      FileMove("%sStartupDir%\%sFile%","%sStartup2Dir%\%sFile%",@FALSE)
      If LastError()>0
         Message("%sTitle% Warning","Could not move file %sFile%.")
      Endif
   Endif
Next

; Get list of all files to execute if unattended.
slFilesToRun=FileItemize("%sStartup2Dir%\*.*")
If StrLen(slFilesToRun)==0 Then Goto EXIT ;nothing to do

; Execute all files if unattended operation.
sMsg="Click here NOW if you want to select which Startup files to run"
bUnattended=!Display(10,"%sTitle% Information",sMsg)
If bUnattended Then Goto RUNFILES

; Not unattended. Let user pick the file(s) to run.
slFilesToRun=AskItemList("Please Select The File(s) To Run",slFilesToRun,@TAB,@UNSORTED,@MULTIPLE)

; Execute the selected file(s) now.
:RUNFILES
For n = 1 To ItemCount(slFilesToRun,@TAB)
   sFile=ItemExtract(n,slFilesToRun,@TAB)
   Run("%sStartup2Dir%\%sFile%","")
Next

; Finished.
Goto EXIT

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
:CANCEL
:EXIT
; Close Key, if open
If bKeyIsOpen
   RegCloseKey(hndKey)
Endif
; Re-establish former error handling mode.
ErrorMode(nPrevErrMode)
; Turn Debug off, just in case..
Debug(@OFF)

Return

Article ID:   W13324
Filename:   AutoStrM-sample from user.txt
File Created: 1999:04:15:16:53:16
Last Updated: 1999:04:15:16:53:16