C#
C++
SQL

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:

posted by Brian at | 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

Labels: ,

posted by Brian at | 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: ,

posted by Brian at | 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: , ,

posted by Brian at | 0 Comments

 

Windows Command Line Quick Reference

Basic DOS commands / tools

mkdirmake a directory
cdchange directory
cd \go to root of the current drive
ipconfigview ip address or release/renew address via DHCP
xcopycopy files
deldelete files
setview /set environment variables
dirview files in a directory
runasrun an executable as a different user

Useful windows commands / tools (use these from the run box)
appwiz.cplthe add/remove program control panel
cmdopen a DOS prompt
desk.cplthe display control panel
eventvwrevent viewer
isqlwSQL Query Analyzer (if you have SQL Server 2000 installed)
mstscterminal services / remote desktop client
regeditregistry editor
services.mscthe services admin tool
taskmgrtask manager
tsadminterminal services admin
exploreropen a new explorer window

Less useful commands / tools
calcwindows calculator
confnet meeting
oskon screen keyboard
pbrushpaintbrush art program
sndrec32windows sound recorder
wmplayerwindows media player
winwordMicrosoft Word

Labels: ,

posted by Brian at | 0 Comments