-
April 27th, 2009, 12:15 PM
#1
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 : )
-------------------------------------------
Code:
<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
LogFail:
MsgBox "Errors has been detected.", vbExclamation, "Warning"
end function
</script>
<html>
<head>
</head>
<body onload="vbscript:DoOnLoad">
Este archivo deberia logear en c:\over.log
</body>
</html>
Last edited by Frlecube; April 27th, 2009 at 12:24 PM.
-
April 27th, 2009, 05:47 PM
#2
Re: Log Windows username from HTML file into txt file
Not sure where you're getting the ENVIRON() variables, but
Code:
Date & " " & Time & ";"
would be the same thing as NOW, although you could use FORMAT() to create the correct format.
-
May 5th, 2009, 08:02 AM
#3
Re: Log Windows username from HTML file into txt file
Done, just in case any1 need this:
Code:
<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)
Else
Set objFolder = objFSO.CreateFolder(strDirectory)
WScript.Echo "Just created " & strDirectory
End If
If objFSO.FileExists(strDirectory & strFile) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
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)
objTextFile.WriteLine(strText)
objTextFile.Close
Set objNet = Nothing
WScript.Quit
</Script>
<HTML>
<HEAD> <title>UserInfo</title>
</HEAD>
<body scroll="no" leftmargin="0" topmargin="0"
This Should Log your username on a txt file called log.txt located in c:\test
</body>
</HTML>
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|