IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Scripting question
Given the following script, named 'userlist.js':
\r\n
\r\n/**\r\n *    Script:   listusers.js\r\n *    Purpose:  Lists all users in a domains.\r\n *    Author:   Daren Thiel \r\n *    Date:     06 Mar 2001 \r\n *    Web:      [link|http://www.winscripter.com|http://www.winscripter.com]\r\n **/\r\n\r\n\r\nshowusers( "PDC-NAME" );\r\n\r\n/**\r\n * showusers - prints list of user accounts and their full names\r\n *             for a given domain.\r\n *\r\n * example   - showusers( "DOMAINNAME" );\r\n *           - showusers( "DOMAINNAME/Computer" );\r\n **/\r\n \r\nfunction showusers( domain )\r\n{\r\n    try\r\n    {\r\n        var users = GetObject( "WinNT://" + domain );\r\n        var e = new Enumerator( users );\r\n        for( ; !e.atEnd(); e.moveNext() )\r\n        {\r\n            var user = e.item();\r\n            if( user.Class == "User" )\r\n            {\r\n                print( "User      : " + user.Name );\r\n                print( "Full Name : " + user.FullName );\r\n                print( "============================" );\r\n            }\r\n        }\r\n    }\r\n    catch( e )\r\n    {\r\n        print( "Error: " + e.description );\r\n    }\r\n}\r\n\r\nfunction print( msg )\r\n{\r\n    WScript.Echo( msg );\r\n}\r\n
\r\n\r\nHow do I change it to export the results to a file, instead of that damn popup window?\r\n
===\r\nMicrosoft offers them the one thing most business people will pay any price for - the ability to say "we had no choice - everyone's doing it that way." -- [link|http://z.iwethey.org/forums/render/content/show?contentid=38978|Andrew Grygus]
New Re: Scripting question
On that site (thanks for that!) you'll see a link for WSH 5.6 beta, which has "improvements handling stdio when working with external programs, such as DOS commands". So that must be the answer. You'd modify the print fn to do something like "echo msg > file".
-drl
New ..and..
..before you drive yourself nuts, remember to call the DOS program with the resulting console window minimized and hidden and autoclosing, or else you'll see it pop up.

There should be a way to invoke Win32 to do this, but for something this simple it's probably not worth the effort.
-drl
New Found the answer
Thanks to Peter for his link to [link|http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vtoriMicrosoftWindowsScriptTechnologies.asp|the horse's mouth]. I followed some links and eventually found [link|http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/jsobjFileSystem.asp|this], based on which the "print" function was rewritten to:\r\n
\r\nfunction print( msg )\r\n   var fso = new ActiveXObject("Scripting.FileSystemObject");\r\n   var a = fso.CreateTextFile("c:\\testfile.txt");\r\n   a.WriteLine( msg );\r\n   a.Close();\r\n}
===\r\nMicrosoft offers them the one thing most business people will pay any price for - the ability to say "we had no choice - everyone's doing it that way." -- [link|http://z.iwethey.org/forums/render/content/show?contentid=38978|Andrew Grygus]
     Scripting question - (drewk) - (3)
         Re: Scripting question - (deSitter) - (1)
             ..and.. - (deSitter)
         Found the answer - (drewk)

Better than an iron-shod boot to the head!
34 ms