Author Topic: Running driver on Windows  (Read 1787 times)

Offline saquivor

  • BFF
  • ***
  • Posts: 110
    • View Profile
Running driver on Windows
« on: November 13, 2006, 06:19:44 AM »
Hi all,



My current activities seem to be keeping me away from LPC right now, but I hope to be back soon:) In the mean time, someone asked me about running ds2 as a service and I have been doing further work with jscript/hta at work s thought I would put an LPC/mudos spin on it at least. Although it relatively easy to get mudos to run as  a service(http://support.microsoft.com/?scid=kb;en-us;137890">MSN help or http://web.mit.edu/cygwin/cygwin_v1.3.2/usr/doc/Cygwin/cygrunsrv.README">Cygwin ), the process of removing the service etc etc is slightly less straight forward, so for me the script is a handy way of running ds2 on a windows machine, when you want to hide the dos driver screen from the main window, to stop people closing it for you!



I decided to post a new version of the script in general forum (old script  here http://lpmuds.net/forum/index.php?webtag=LPC&msg=80.1">here ) as it will help anyone who runs mudos on windows, not just ds2. This script needs to be saved as somefilename.hta to run or click http://www.monkeyx.net/MyMud.hta">here to download it.   To run the script just double click on it and it will auto run driver, the buttons will explain the rest, once running.  



Any feedback appreciated.



You can also download file http://www.monkeyx.net/MyMud.hta">here.



code:

<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Run mudos driver</TITLE>
</HEAD>

<Script Language=JScript>
var wbemFlagReturnImmediately = 0x10; //move to function?
var wbemFlagForwardOnly = 0x20;
var WinMgmts,ProcessName="driver.exe",wind=0;
var oShell=new ActiveXObject("WScript.Shell");
var mudhome="C:/ds/win32/"; //Path to driver

function Load() {
StatusId.innerHTML = "initializing";
var iTimerID = window.setInterval("UpdateService()",2500);
}

function UpdateService() {
var CheckStatus="Driver Not loaded";
var dDate=new Date();
if (HiddenWindow.checked){
   wind=1;
   }
else
   wind=0;
try {
   var WinMgmts = GetObject( "winmgmts://./root/cimv2" );
   }
catch(e)  {alert("Error in script: " + e);}
   var colItems = WinMgmts.ExecQuery("SELECT * FROM Win32_Process where Name='" + ProcessName +
    "'", "WQL",wbemFlagReturnImmediately | wbemFlagForwardOnly);
   var enumItems = new Enumerator(colItems);
      var objItem = enumItems.item();

      if (enumItems.atEnd() && !StopDriver.checked) //Checks if collection empty, will be true if so run the driver
      {
      CheckStatus = "Loading driver.exe";      
      oShell.Run ("%comspec% /c " + mudhome +  ProcessName +
      " c:/ds/lib/secure/cfg/mudos.cfg >C:/ds/driver_log.txt",wind,false); //redirect not sending much to file
      }
try {
   CheckStatus=objItem.Name+" is loaded ";
   }
catch(e)  {CheckStatus="Driver not loaded " + e;}

   StatusId.innerHTML = CheckStatus+" at "+dDate.getHours()+":"
   +dDate.getMinutes()+":"+dDate.getSeconds();
}


function ReLoad(){
location.reload(true)
}
function KillDriver() {
try {
   var WinMgmts = GetObject( "winmgmts://./root/cimv2" );
   }
   catch(e)  {alert("Error in script: " + e);}
var colItems = WinMgmts.ExecQuery("SELECT * FROM Win32_Process where Name='" + ProcessName +
 "'", "WQL",wbemFlagReturnImmediately | wbemFlagForwardOnly);
var enumItems = new Enumerator(colItems);
var objItem = enumItems.item();

if (!enumItems.atEnd()) //Checks if collection empty, will be true if so run the driver
      {
      objItem.Terminate();
      }
else
      {
      StatusId.innerHTML = "<p>Driver is not running, so can not end task<p>";      
      }
}
</Script>

<BODY OnLoad="Load()">
<h1>Status of mudos driver.exe</h1>
<table width="100%" border>
<tr>
<td>Driver Status:</td>
<td>
<Div Id="StatusId"></Div>
</td>

</tr>
<tr>
<td width=50%><Button Id="ReLoadButton" OnClick="ReLoad()" title="Click here to reset back to default values">Load Defaults</Button></td>
<td><Button Id="KillDriver" OnClick="KillDriver()" title="Click here to kill driver.exe.">Kill Driver</Button></td>
</tr>
<tr>
<td><input type="checkbox"name="HiddenWindow"value="1"> Tick to show Driver Window</td>
<td><input type="checkbox"name="StopDriver"value="1"> Tick to Stop driver auto restarting</td>
</tr>
<tr>
<td>Will need to kill driver to allow window to restart in open mode</td>
<td>This tick box does not kill the driver.</td>
</tr>
</table>
<p><p>
Beta version all feedback to <a href="mailto:saquivor@monkeyx.net">Saquivor</a></td>
</BODY>
</HTML>