Executing a program at startup
Run and RunOnce registry keys cause programs to run each time that a user logs on. The data value for a key is a command line. Register programs to run by adding entries of the form description-string=commandline. You can write multiple entries under a key. If more than one program is registered under any particular key, the order in which those programs run is indeterminate.
The Windows registry includes the following four keys:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce
By default, the value of a RunOnce key is deleted before the command line is run. You can prefix a RunOnce value name with an exclamation point (!) to defer deletion of the value until after the command runs. Without the exclamation point prefix, if the RunOnce operation fails the associated program will not be asked to run the next time you start the computer.
By default, these keys are ignored when the computer is started in Safe Mode. The value name of RunOnce keys can be prefixed with an asterisk (*) to force the program to run even in Safe mode.
For more information, check out these articles:
http://support.microsoft.com/kb/179365
http://msdn.microsoft.com/en-us/library/aa376977(VS.85).aspx
Labels: Windows
posted by Brian at 9/08/2008 09:45:00 PM | 0 Comments
VBScript - Quick and dirty file downloader
usage: cscript script.vbs "http://www.myurl.com/myfile.jpg", "C:\output\myfile.jpg"Set oArgs = WScript.Arguments
If oArgs.Count <> 2 Then
Wscript.Echo "Error: Wrong number of arguments!"
Wscript.Quit 1
End If
strDownloadURL = oArgs(0)
strSaveAsURL = oArgs(1)
Set oHttp = CreateObject("Microsoft.XMLHTTP")
oHttp.open "GET", strDownloadURL, false
oHttp.send()
If oHttp.status <> 200 Then
WScript.Echo "Failed getting the file: " & strDownloadURL & vbCrLf & "Error: " & oHttp.statusText
WScript.Quit 2
End If
SaveFileToDisk strSaveAsURL, oHttp.ResponseBody
Function SaveFileToDisk(strFileName, oData)
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
Dim oStream: Set oStream = CreateObject("ADODB.Stream")
oStream.Type = adTypeBinary
oStream.Open
oStream.Write oData
oStream.SaveToFile strFileName, adSaveCreateOverWrite
Set oStream = Nothing
End Function
posted by Brian at 9/08/2008 04:17:00 PM | 0 Comments
Waiting for msiexec.exe to complete
If you just invoke an MSI package from the command line, msiexec will execute asynchronously. To get around this you can use start /wait from your batch file. This will create the process and wait for it to exit. Type start /wait before the command line you'd normally pass to msiexec.exe like so:start /wait msiexec.exe /i MyMSI.msi /l*v MyMSI.log
The batch file would be blocked until msiexec.exe finishes. Programmatically this is the same as invoking msiexec.exe with CreateProcess and waiting for the process to return from WaitForSingleObject with no timeout.
Labels: Command Line, Windows
posted by Brian at 9/04/2008 12:25:00 PM | 1 Comments
Logging in automatically in Windows
On every media center PC I've used, most of the usage didn't involve a keyboard. With Windows Media Center Edition 2005 I mostly used the MCE remote control and with my new Windows Vista machine I use a touch screen.
One obstacle for getting the perfect setup on your media center is the logging in process. On Windows XP or Vista you'll have to click a Windows XP user icon (or enter a username) and enter the password (if applicable) to log in. I want to have a password to protect shared content but I don't want to have to actually log in or click the frog Windows XP user icon next to the name "Brian". I want my user account to automatically log in and have it run a startup script, open up commonly used programs, etc. There is a fix available for Windows XP / Windows Vista.
Use the Start Menu -> Run to pull up the run box (or on Vista, just pull up the start menu and click on the "start search") and type in "control userpasswords2". Hit enter and you will be presented with a "User Accounts" dialog. Simply uncheck the "Users must enter a user name and password to use this computer" box. When you click "Apply" or "OK", the dialog will prompt you with the credentials you want to use to automatically log in. Enter the user you would like to be automatically logged in and you're ready to go.
Labels: Windows, Windows Vista, Windows XP
posted by Brian at 5/28/2008 08:40:00 PM | 0 Comments
Windows Command Line Quick Reference
Basic DOS commands / tools
| mkdir | make a directory |
| cd | change directory |
| cd \ | go to root of the current drive |
| ipconfig | view ip address or release/renew address via DHCP |
| xcopy | copy files |
| del | delete files |
| set | view /set environment variables |
| dir | view files in a directory |
| runas | run an executable as a different user |
Useful windows commands / tools (use these from the run box)
| appwiz.cpl | the add/remove program control panel |
| cmd | open a DOS prompt |
| desk.cpl | the display control panel |
| eventvwr | event viewer |
| isqlw | SQL Query Analyzer (if you have SQL Server 2000 installed) |
| mstsc | terminal services / remote desktop client |
| regedit | registry editor |
| services.msc | the services admin tool |
| taskmgr | task manager |
| tsadmin | terminal services admin |
| explorer | open a new explorer window |
Less useful commands / tools
| calc | windows calculator |
| conf | net meeting |
| osk | on screen keyboard |
| pbrush | paintbrush art program |
| sndrec32 | windows sound recorder |
| wmplayer | windows media player |
| winword | Microsoft Word |
Labels: Command Line, Windows
posted by Brian at 4/02/2008 09:01:00 PM | 0 Comments