Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 20th, 2005, 06:01 AM
Authorized User
 
Join Date: May 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Looney
Default running Wmi Scripts in ASP.NET

Hi All ,
 I am a newbie to WMI scripting , I am aware of the fact that u can run these scripts through Jscript , Vb script, perl and Python to produce output in Html and XMl .Much of it i gathered from info on Microsft 's site and tutorials etc. What i am currently trying to acheieve is to gather information /if possible copy over a copy of all installed drivers from my asp.net client(who is running the application in the browser) to the server side ,I have a script which retrieves all there is too know about these drivers from wmi and it executes on my machine if i run it through a browser , but what i wanna do it to run it through my IIS web server , could some one please point me in the right direction by telling me, the steps involved in order for my code to do so.Plus once i know the physical locations of these drivers what possible mechanism can i use from client side / server side to copy those drivers into a directory on my server.Is it even possible to do so .From what appears from my research is that it is possible to connect to wmi service on a remote machine and to gather info , is it possible to make copies of those files somehow if u know the path say like (H:\WINDOWS\system32\drivers\ALCXWDM.SYS), if so what sort a security restrictions problems i would be facing and how to go by , to overcome them .Thanxs in advance .here is the wmi script .
var wbemFlagReturnImmediately = 0x10;
var wbemFlagForwardOnly = 0x20;

var arrComputers = new Array("BULLET");
for (i = 0; i < arrComputers.length; i++) {
   WScript.Echo();
   WScript.Echo("==================================== ======");
   WScript.Echo("Computer: " + arrComputers[i]);
   WScript.Echo("==================================== ======");

   var objWMIService = GetObject("winmgmts:\\\\" + arrComputers[i] + "\\root\\CIMV2");
   var colItems = objWMIService.ExecQuery("SELECT * FROM Win32_SystemDriver", "WQL",
                                          wbemFlagReturnImmediately | wbemFlagForwardOnly);

   var enumItems = new Enumerator(colItems);
   for (; !enumItems.atEnd(); enumItems.moveNext()) {
      var objItem = enumItems.item();

      WScript.Echo("AcceptPause: " + objItem.AcceptPause);
      WScript.Echo("AcceptStop: " + objItem.AcceptStop);
      WScript.Echo("Caption: " + objItem.Caption);
      WScript.Echo("CreationClassName: " + objItem.CreationClassName);
      WScript.Echo("Description: " + objItem.Description);
      WScript.Echo("DesktopInteract: " + objItem.DesktopInteract);
      WScript.Echo("DisplayName: " + objItem.DisplayName);
      WScript.Echo("ErrorControl: " + objItem.ErrorControl);
      WScript.Echo("ExitCode: " + objItem.ExitCode);
      WScript.Echo("InstallDate: " + WMIDateStringToDate(objItem.InstallDate));
      WScript.Echo("Name: " + objItem.Name);
      WScript.Echo("PathName: " + objItem.PathName);
      WScript.Echo("ServiceSpecificExitCode: " + objItem.ServiceSpecificExitCode);
      WScript.Echo("ServiceType: " + objItem.ServiceType);
      WScript.Echo("Started: " + objItem.Started);
      WScript.Echo("StartMode: " + objItem.StartMode);
      WScript.Echo("StartName: " + objItem.StartName);
      WScript.Echo("State: " + objItem.State);
      WScript.Echo("Status: " + objItem.Status);
      WScript.Echo("SystemCreationClassName: " + objItem.SystemCreationClassName);
      WScript.Echo("SystemName: " + objItem.SystemName);
      WScript.Echo("TagId: " + objItem.TagId);
   }
}

function WMIDateStringToDate(dtmDate)
{
   if (dtmDate == null)
   {
      return "null date";
   }
   var strDateTime;
   if (dtmDate.substr(4, 1) == 0)
   {
      strDateTime = dtmDate.substr(5, 1) + "/";
   }
   else
   {
      strDateTime = dtmDate.substr(4, 2) + "/";
   }
   if (dtmDate.substr(6, 1) == 0)
   {
      strDateTime = strDateTime + dtmDate.substr(7, 1) + "/";
   }
   else
   {
      strDateTime = strDateTime + dtmDate.substr(6, 2) + "/";
   }
   strDateTime = strDateTime + dtmDate.substr(0, 4) + " " +
   dtmDate.substr(8, 2) + ":" +
   dtmDate.substr(10, 2) + ":" +
   dtmDate.substr(12, 2);
   return(strDateTime);
}

Regards
Looney

Looney!
__________________
Looney!
 
Old May 20th, 2005, 09:46 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Unless the client has extremely low security settings then this won't work. If they have, perhaps it is on your intranet and you can dictate settings, then you need the script as is, except that instaed of WScript.echo-ing the data you need to build it into some sort of string and then post the data to the server using standard HTML forms. You will also need to target the local machine, so the start should read:
Code:
var arrComputers = new Array(".");


--

Joe (Microsoft MVP - XML)
 
Old May 20th, 2005, 10:28 AM
Authorized User
 
Join Date: May 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Looney
Default

Hi Joe ,
        Firstly thanxs a million for your reply and for an insight on the topic . I was in state of doing some more research and was wondering would it be easier to do this and would it have a higher probability to run with an Activex object instead .probably a MFC++ active X object or an ATL one perhaps .See i am new to this so i am sorta facing these questions one after another without knowing if i am heading in the right direction ,What if i was to plan to create a secure digital activex object instead to run this script or to do the same through c++ code and after Creating a Test Certificate for an ActiveX Control would i be able to get it running on any machine on the web which would accept sign the certificate . Look i sorta feel a little lost , would very greatly appreciate if u could point me to the right direction , and if possible even point me to resources on web which could help me get something running by monday .Thanxs in advance .

Looney!
 
Old May 20th, 2005, 01:30 PM
Authorized User
 
Join Date: May 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Looney
Default

Hi All,What would be easiest way to be able to technologicaly create a web page which could update windows files just like Microsoft's Windows Update site does ? I actually need to try to copy drivers over the wire to a directory on Server froma client machine ?is it it even possible to do so by using any technological means out there , if so then which ones , not third party applications , but something which can build this up . I hope u get my drift :-) Thanxs in advance !

Looney!





Similar Threads
Thread Thread Starter Forum Replies Last Post
running asp.net scripts owoade .NET Web Services 3 August 27th, 2007 08:06 PM
Calling WMI from ASP.Net Web Page vikingsunil ASP.NET 1.0 and 1.1 Professional 1 June 28th, 2007 08:54 AM
Calling WMI from ASP.Net Web Page vikingsunil ASP.NET 1.0 and 1.1 Professional 0 June 7th, 2007 05:19 AM
How to make a WMI call from an ASP.Net Page vikingsunil VS.NET 2002/2003 0 June 7th, 2007 05:08 AM
ASP.NET Server Controls and Client-Side Scripts LoneStar1 BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 5 March 15th, 2006 05:51 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.