Yzöwl Posted January 1, 2015 Share Posted January 1, 2015 Ok, don't get this. Here is what I have:[SNIP /]Rem Start TrackIRcd C:\Program Files (x86)\NaturalPoint\TrackIR5start TrackIR5.exeTimeout 5 1>NulRem Start Steam Directlycd D:\Applications\SteamStart Steam.exeTimeout 5 1>NulRem Start IL-2 Directlycd C:\Games\SteamLibrary\SteamApps\common\IL-2 Sturmovik Cliffs of DoverStart Launcher.exeIt isn't making the switch to d drive. I've tried entering it manually into the command prompt cd d:\ but nothing, it stays in the c: drive. Any suggestions? Nevermind, I found it. I need to use the /D switchWhy are you even bothering changing directories?@Echo Off & SetLocal DisableDelayedExpansionSet "_BD=%UserProfile%\Documents\1C SoftClub\il-2 sturmovik cliffs of dover - MOD\DashPics"If "%CD%" NEq "%_BD%" PushD %_BD%||Exit/BSet "_$="For %%# In (Templates\*.tga) Do Set/A _$+=1 & For /F %%_ In ('Call Echo(%%_$%%' ) Do Set "_F[%%_]=%%#"Set/A _R=%Random% %% _$ +1Call Echo(Processing "%%_F[%_R%]%%"Call Copy "%%_F[%_R%]%%" Selected\1.tga>NulStart "" "%ProgramFiles(x86)%\NaturalPoint\TrackIR5\TrackIR5.exe"Start "" "D:\Applications\Steam\Steam.exe"Start "" "C:\Games\SteamLibrary\SteamApps\common\IL-2 Sturmovik Cliffs of Dover\Launcher.exe"I've removed all of the five second pauses so if your executables are launching too quickly then use the /Wait switch with Start. Also be aware that whilst you've asked for the script to not be user specific, you've then fixed the locations for steam.exe and launcher.exe! Link to comment Share on other sites More sharing options...
MHz Posted January 2, 2015 Share Posted January 2, 2015 (edited) I am a rather new with PowerShell though here is an example. It started lean, yet testing threw errors that I addressed i.e non existing paths etc. Tested with PowerShell 4.0.<#.DESCRIPTIONCan use this to run a program..EXAMPLEStart-Program "Notepad.exe"#>function Start-Program { # Last 3 parameters are optional param ($filename, $program_dir = '', $sleep = 0, $on_error = 'Continue') if ($program_dir -and $filename) { $filepath = join-path $program_dir $filename } else { $filepath = $filename } Start-Process -FilePath "$filepath" -ErrorAction $on_error Start-Sleep -Seconds $sleep}# Destination value$destination = "$env:UserProfile\Documents\1C SoftClub\il-2 sturmovik cliffs of dover - MOD\DashPics"# Test path "$destination\Selected"if (-not(test-path "$destination\Selected")) { New-Item -Path "$destination\Selected" -ItemType 'directory' -Force -Confirm if (-not(test-path "$destination\Selected")) { "You chose not to create `"$destination\Selected`"" Start-Sleep -Seconds 5 exit }}# Test path "$destination\Templates"if (-not(test-path "$destination\Templates")) { New-Item -Path "$destination\Templates" -ItemType 'directory' -Force -Confirm "Add tga files to `"$destination\Templates`" and then restart this script" Start-Sleep -Seconds 5 exit}# Recursive search for *.tga files in "$destination\Templates"$files = Get-ChildItem "$destination\Templates" -Include "*.tga" -Recurseif (! $files.Count) { Write-Error 'No tga files found' exit 1} elseif ($files.Count -eq 1) { # Just 1 item so assign the integer and the item $random = 1 $target = $files.FullName} else { # Get a random integer between 0 and the count of files $random = Get-Random -Maximum $files.Count # Get the fullname based on the random item $target = $files.GetValue($random).FullName}# Add the filename to the destination path$destination += '\Selected\1.tga'# Copy the source item to the destinationCopy-Item $target $destination -Force# Write out a summary"Count: " + $files.Count + "`r`nRandom: $random`r`nTarget: $target`r`nDestination: $destination"# Cleanup some variables and then sleepRemove-Variable files,randomStart-Sleep -Seconds 5# Start Wordpad. Test only with a user defined function instead of repeating codeStart-Program 'wordpad.exe' "${env:ProgramFiles(x86)}\Windows NT\Accessories" 1 'Stop'# Start TrackIR. "-ErrorAction 'Stop'" parameter exits the script if error occurs$program_dir = "${env:ProgramFiles(x86)}\NaturalPoint\TrackIR5"Start-Process "$program_dir\TrackIR5.exe" -WorkingDirectory "$program_dir" -ErrorAction 'Stop'Start-Sleep -Seconds 1# Start Steam Directly$program_dir = "D:\Applications\Steam"Start-Process "$program_dir\Steam.exe" -WorkingDirectory "$program_dir" -ErrorAction 'Stop'Start-Sleep -Seconds 1# Start IL-2 Directly$program_dir = "C:\Games\SteamLibrary\SteamApps\common\IL-2 Sturmovik Cliffs of Dover"Start-Process "$program_dir\Launcher.exe" -WorkingDirectory "$program_dir" -ErrorAction 'Stop'# Final variable cleanupRemove-Variable destination,target,program_dir Edit: The Documents folders is a Shell Folder. I have no Shell Folders in %UserProfile% as they exist on another partition on the main drive and the system has recorded this move. The code below is a registry option to get a path of a Shell Folder i.e "Personal" which is the My Documents path. I chose not to change the code above with this code and leave it as an option.# ScriptBlock Purpose: Get a shell folder path.$MyDocumentsPath = & { param ($Name) $ShellFolders = Get-ItemProperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders' Return $ShellFolders.$Name} Personal # Arg: Registry name to get data from."My Documents path: `"$MyDocumentsPath`"" Edited January 3, 2015 by MHz Link to comment Share on other sites More sharing options...
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