CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 3 of 3

Thread: Log Windows username from HTML file into txt file

  1. #1
    Join Date
    Apr 2009

    Log Windows username from HTML file into txt file

    Hi, I have the following code on and html file, but i cant make it work,
    Any Ideas ??? Please help : )
    <script language="vbscript">
    function DoOnLoad()
    Declare Function GetSystemMetrics Lib "user32.dll" (ByVal nIndex As Long) As Long 
    On Error GoTo LogFail
        Dim filenum As Integer
        Dim i As Integer
        Dim fic As String
        filenum = FreeFile
        logfile = "C:\over.log"
        Open logfile For Append As filenum
        Print #filenum, Date & " " & Time & ";" & Environ("UserName") & ";" & Environ("ComputerName") & ";"
        Close filenum
    MsgBox "Errors has been detected.", vbExclamation, "Warning"
    end function
    <body onload="vbscript:DoOnLoad">
    Este archivo deberia logear en c:\over.log
    Last edited by Frlecube; April 27th, 2009 at 12:24 PM.

  2. #2
    Join Date
    Jan 2006
    Fox Lake, IL

    Re: Log Windows username from HTML file into txt file

    Not sure where you're getting the ENVIRON() variables, but
    Date & " " & Time & ";"
    would be the same thing as NOW, although you could use FORMAT() to create the correct format.

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Apr 2009

    Re: Log Windows username from HTML file into txt file

    Done, just in case any1 need this:

    <Script Language="VBScript">
    Option Explicit
    Dim objFSO, objFolder, objShell, objTextFile, objFile
    Dim strDirectory, strFile, strText
    Dim objNet
    strDirectory = "C:\test"
    strFile = "\log.txt"
    On Error Resume Next 
    Set objNet = CreateObject("WScript.NetWork")
    strText = Now & ";" & objNet.UserName & ";" &objNet.ComputerName & ";;;"
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If objFSO.FolderExists(strDirectory) Then
       Set objFolder = objFSO.GetFolder(strDirectory)
       Set objFolder = objFSO.CreateFolder(strDirectory)
       WScript.Echo "Just created " & strDirectory
    End If
    If objFSO.FileExists(strDirectory & strFile) Then
       Set objFolder = objFSO.GetFolder(strDirectory)
       Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
       Wscript.Echo "Just created " & strDirectory & strFile
    End If 
    set objFile = nothing
    set objFolder = nothing
    Const ForAppending = 8
    Set objTextFile = objFSO.OpenTextFile _
    (strDirectory & strFile, ForAppending, True)
    Set objNet = Nothing 
    <HEAD> <title>UserInfo</title>
    <body scroll="no" leftmargin="0" topmargin="0"
    This Should Log your username on a txt file called log.txt located in c:\test

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)