title: Putting script in windows startup
body: <p>I'm trying to write code that puts itself in windows start-up and runs on boot using vbs. I wrote one that copies the file to the startup folder, but doesn't execute when the system boots.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>Set objShell = Wscript.CreateObject("Wscript.Shell")
  strPath = objShell.SpecialFolders("Startup")
  strMyPath = strPath&amp;"\"  
  Const SourceFile = "a.vbs"
  strMyPath = strMyPath &amp; SourceFile
  Set fso = CreateObject("Scripting.FileSystemObject")
  
  'Check to see if the file already exists in the destination folder
  If fso.FileExists(strMyPath) Then
  
  'Check to see if the file is read-only
  If Not fso.GetFile(strMyPath).Attributes And 1 Then 
      'The file exists and is not read-only.  Safe to replace the file.
      fso.CopyFile SourceFile, strMyPath, True
  Else 
      'The file exists and is read-only.
      'Remove the read-only attribute
      fso.GetFile(strMyPath).Attributes = fso.GetFile(strMyPath).Attributes - 1
      'Replace the file
      fso.CopyFile SourceFile, strMyPath, True
      'Reapply the read-only attribute
      fso.GetFile(strMyPath).Attributes = fso.GetFile(strMyPath).Attributes + 1
  End If
  Else
  'The file does not exist in the destination folder.  Safe to copy file to this folder.
  fso.CopyFile SourceFile, strMyPath, True
  End If
  Set fso = Nothing
  </code></pre>