p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Classic ASP Basics (http://p2p.wrox.com/forumdisplay.php?f=61)
-   -   WScript (http://p2p.wrox.com/showthread.php?t=6918)

RTC December 5th, 2003 10:55 AM

WScript
 
Hi,
can anybody help with some WScript as I am completely new to this.
I am working in an intranet environment and basically need to do the following:
1: Access the computer name of a user, who is calling an asp page
2: Get the active printer of that user and change it's settings
3: Print out an asp page with the new printer settings

can this be done?
I have played around a bit with WScript, but can't seem to get the computer name of the user (or it always returns the server name, where the asp script is run at) and when I try to run the following code I get the error message "Error Type:(0x80041003)", it errors on GetObject(), which I think means I don't have permission to do the following:

function TranslateDomainRole(byVal roleID)
    Dim a

    Select Case roleID
        Case 0
            a = "Standalone Workstation"
        Case 1
            a = "Member Workstation"
        Case 2
            a = "Standalone Server"
        Case 3
            a = "Member Server"
        Case 4
            a = "Backup Domain Controller"
        Case 5
            a = "Primary Domain Controller"
    End Select
    TranslateDomainRole = a
end function

Dim s, System, item
Set System = GetObject("winmgmts:").instancesOf("Win32_Computer System")
for each item in system'
    s = "Computer Info" & vbcrlf
    s = s & "***********************" & vbcrlf
    s = s & "Name: " & item.name & vbcrlf
    s = s & "Status: " & item.status & vbcrlf
    s = s & "Type: " & item.SystemType & vbcrlf
    s = s & "Mfg: " & item.Manufacturer & vbcrlf
    s = s & "Model: " & item.Model & vbcrlf
    s = s & "RAM: ~" & item.TotalPhysicalMemory\1024000 & "mb" & vbcrlf
    s = s & "Domain: " & item.Domain & vbcrlf
    s = s & "Role: " & TranslateDomainRole(item.DomainRole) & vbcrlf
    s = s & "Current User: " & item.UserName & vbcrlf
    wscript.echo s
next


any help is greatly appreciated...



Imar December 5th, 2003 01:24 PM

Hi there,

How are you running this code? Between <% and %> or between client side VBScript tags (<script>)?

If you're using <% the code will run on the server, so the server name is returned.

Make sure you run the code at the client if you want to retrieve the client's name. Also, make sure you have sufficient permissions (the website needs permissions) to run the script at the client. You probably need to add the server to the Trusted Sites of IE.


HtH,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.

raajaindra June 8th, 2005 04:03 AM

Following is the source of ASP
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonat e}!\\" & strComputer & "\root\cimv2")
set objRefresher = CreateObject("WbemScripting.SWbemRefresher")
Set objMemory = objRefresher.AddEnum (objWMIService, "Win32_PerfFormattedData_PerfOS_Memory").objec tSet
objRefresher.Refresh

Do
    For Each intAvailableBytes in objMemory
        If intAvailableBytes.AvailableMBytes < 4 Then
            Wscript.Echo "Available memory has fallen below 4 megabytes."
        End If
    Next
    objRefresher.Refresh
Loop

...and following is the error thrown by the browser
Technical Information (for support personnel)

Error Type:
(0x80041003)
/aa/lisTrusted.asp, line 17


Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)

Page:
GET /aa/lisTrusted.asp

Time:
Wednesday, June 08, 2005, 11:31:00 AM
...what could be the reason
please help....
raajaindra



All times are GMT -4. The time now is 08:41 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.