Jump to content
Sign in to follow this  
PeterAtkin

[Solved] StarCraft Windows 7 loader

Recommended Posts

PeterAtkin

had some time on my hand and started to play some of my older games with some friends, found that StarCraft was giving issues under Windows 7, while this script works I have a sneaking feeling that the ProcessWaitClose function is not working as I had anticipated, that why I had to put a sleep command in.

I woukld like the run_application() function to stop processing until the application process is no longer running, hope I am making sence here.

Would it be possible to point out where my logic is faulty, as this scrip once completed would be useful for other programs / games done in the same era.

; StarCraft Windows 7 Loader<BR>; remeber to make sure that in the StarCraft compatabilty properties tick all the settings tick boxes,<BR>; leave Compatability mode and Prilege Level unticked.<BR><BR><BR>kill_process("skypePM.exe")<BR>kill_process("skype.exe")<BR>kill_process("skypenames2.exe")<BR>kill_process("explorer.exe")<BR>ShellExecute("desk.cpl", @SystemDir)<BR>run_application("StarCraft.exe", "D:\Games\Starcraft\")<BR>start_process("explorer.exe")<BR>;start_process("skype.exe")<BR><BR>Func kill_process($process)<BR>If ProcessExists($process) Then<BR>  ProcessClose($process)<BR>EndIf<BR>EndFunc   ;==>kill_process<BR><BR>Func start_process($process)<BR>If ProcessExists($process) Then<BR>Else<BR>  Run($process)<BR>EndIf<BR>EndFunc   ;==>start_process<BR><BR>Func run_application($application, $directory)<BR>ShellExecute($application, "", $directory)<BR>Sleep(3000)<BR>$PID = Run($application)<BR>ProcessWaitClose($PID)<BR>EndFunc   ;==>run_application<BR><BR>; T.D.L<BR>; find a way to close the desk.cpl windows without resorting to recording mouse movements.<BR>; ProcessWaitClose($PID) seems not to be working?<BR>; way to automatically make sure that the application compatibility properties are all ticked
Edited by PeterAtkin

[topic='115020'] AD Domain Logon Script[/topic]

Share this post


Link to post
Share on other sites
dani

Why do you think it doesn't work? You use it right so I actually assume it will work this way. Try a MsgBox( ... ) after the ProcessWaitClose() function and see if it actually launches that while the program is running.

Btw please change

Func start_process($process)
  If ProcessExists($process) Then
  Else
    Run($process)
  EndIf
EndFunc   ;==>start_process

To

Func start_process($process)
  If Not ProcessExists($process) Then Run($process)
EndFunc   ;==>start_process

:mellow:

Edited by dani

Share this post


Link to post
Share on other sites
Xand3r

RunWait maybee?


Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Share this post


Link to post
Share on other sites
dani

No let's first investigate why ProcessWaitClose doesn't work -- or does. If there's a problem with a function you don't understand it's bad practice IMO to just switch to something else. Effectively giving up on learning how you should use the other function in the first place :mellow:

Share this post


Link to post
Share on other sites
PeterAtkin

As I understand the code below should work as follows.

1) Run the application with the ShellExecute (this works)

2) Setup a local variable $PID to add the running application to the $PID variable (do not understand that fully as would it not be the same as doing

ProcessWaitClose($application)
)

3) Wait for said application process to stop before leaving the function.

Func run_application($application, $directory)
ShellExecute($application,"", $directory)
$PID = Run($application)
ProcessWaitClose($PID)
EndFunc   ;==>run_application

Currently the code does not stop at stage 3 it continues so it seems, as when I put a another piece of code after the ProcessWaitClose line it continues, i belive i have check the process it exists as StarCraft.exe so I am baffled.

@dani thanks for the understanding I really want to learn and now tripping over some fundamentals I guess.

Full code with testing below

; StarCraft Windows 7 Loader
; remeber to make sure that in the StarCraft compatabilty properties tick all the settings tick boxes,
; leave Compatability mode and Prilege Level unticked.

#include <EventLog.au3>

kill_process("skypePM.exe")
kill_process("skype.exe")
kill_process("skypenames2.exe")
ShellExecute("desk.cpl", @SystemDir)
run_application("StarCraft.exe", @WorkingDir & "\")

Func kill_process($process)
If ProcessExists($process) Then
  ProcessClose($process)
  If @error Then
   _put_event(1, "prcocess :" & $process & " not terminated", @error)
  Else
   _put_event(4, "prcocess :" & $process & " terminated", @error)
  EndIf
EndIf
EndFunc   ;==>kill_process

Func start_process($process)
If Not ProcessExists($process) Then Run($process)
EndFunc   ;==>start_process

Func run_application($application, $directory)
ShellExecute($application, "", $directory)
If @error Then
  _put_event(1, "Application :" & $application & " not not started", @error)
Else
  _put_event(4, "Application :" & $application & " stared", @error)
EndIf
$PID = Run($application)
ProcessWaitClose($PID)
MsgBox(1, $application, "why am i here")

EndFunc   ;==>run_application

Func _put_event($value, $text, $error_id_code)
;SUCCESS = 0
;ERROR =1
;WARNING =2
;INFORMATION =4
;AUDIT_SUCCESS =8
;AUDIT_FAILURE =16
Local $hEventLog, $aData[4] = [3, 1, 2, 3]

$hEventLog = _EventLog__Open("", "StarCraft Loader")
_EventLog__Report($hEventLog, $value, 0, $error_id_code, @UserName, @CRLF & $text, $aData)
_EventLog__Close($hEventLog)
EndFunc   ;==>_put_event

; T.D.L
; find a way to close the desk.cpl windows without resorting to recording mouse movements.
; ProcessWaitClose($PID) seems not to be working?
; way to automatically make sure that the application compatibility properties are all ticked
Edited by PeterAtkin

[topic='115020'] AD Domain Logon Script[/topic]

Share this post


Link to post
Share on other sites
PeterAtkin

OK ithe $PID is the numeric representation of the StarCraft.exe process running! I'm still none tyhe wiser for the solution to this problem but I am wiser.


[topic='115020'] AD Domain Logon Script[/topic]

Share this post


Link to post
Share on other sites
PeterAtkin

OK Solved thanks to both of you, put in the runwait as per Zand3r advice all works well and now I think i have a handle on how to close the desk.cpl thanks to dani pushing the learning curve.. full working code to date below.

#include <EventLog.au3>
#include <Array.au3>

Global $KillApp[4]
$KillApp[1] = "skype.exe"
$KillApp[2] = "skypePM.exe"
$KillApp[3] = "skypenames2.exe"

kill_before_application()
ShellExecute("desk.cpl", @SystemDir & "\")
Sleep (2000)
run_application("StarCraft.exe", @WorkingDir & "\")

Func kill_before_application()
 For $i = 1 To $KillApp[0] Step 1
  If ProcessExists($KillApp[$i]) Then
   ProcessClose($KillApp[$i])
   If @error Then
    _put_event(1, "Application :" & $KillApp[$i] & " not terminated", @error)
   Else
    _put_event(4, "Application :" & $KillApp[$i] & " terminated", @error)
   EndIf
  EndIf
 Next
EndFunc   ;==>kill_before_application

Func kill_after_application($PID)
 If ProcessExists($PID) Then
  ProcessClose($PID)
  If @error Then
   _put_event(1, "process :" & $PID & " not terminated", @error)
  Else
   _put_event(4, "process :" & $PID & " terminated", @error)
  EndIf
 EndIf
EndFunc   ;==>kill_after_application

Func start_application($process)
 If Not ProcessExists($process) Then Run($process)
EndFunc   ;==>start_application

Func run_application($application, $directory)
 Local $val = RunWait($application, $directory, @SW_MAXIMIZE)
 If @error Then
  _put_event(1, "Application :" & $application & " not started exit code :" & $val, @error)
 Else
  _put_event(4, "Application :" & $application & " stared", @error)
 EndIf
EndFunc   ;==>run_application

Func _put_event($value, $text, $error_id_code)
 ;SUCCESS = 0
 ;ERROR =1
 ;WARNING =2
 ;INFORMATION =4
 ;AUDIT_SUCCESS =8
 ;AUDIT_FAILURE =16
 Local $hEventLog, $aData[4] = [3, 1, 2, 3]

 $hEventLog = _EventLog__Open("", "StarCraft Loader")
 _EventLog__Report($hEventLog, $value, 0, $error_id_code, @UserName, @CRLF & $text, $aData)
 _EventLog__Close($hEventLog)
EndFunc   ;==>_put_event

; T.D.L
; Need to find a way to close tyhe desk.cpl process
; way to automatically make sure that the application compatibility properties are all ticked
Edited by PeterAtkin

[topic='115020'] AD Domain Logon Script[/topic]

Share this post


Link to post
Share on other sites
PeterAtkin

Now does anyone have any ideas how to close the desk.cpl process as it seems I've tried and failed, seems i can't fine the Process ID or Process name that this uses which seems to be the key to closing it. I used among other this

$PID = ShellExecute("desk.cpl", @SystemDir & "\")
but that only brought me a process ID of 1 that did not exist as far as I could tell.

Edited by PeterAtkin

[topic='115020'] AD Domain Logon Script[/topic]

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×