|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||||
|
|||||
|
Login Script - Saving to database help
Hello everyone. I currently have a login script that I will post at the end of this post, but it basiaclly writes the following information to a text file:
User Name Computer Name Date / Time IP Address Example output Logon , 11/12/2007 3:37:15 PM , MRB*** , go**** , 10.192.***.** I need to figure out how to write this information into a database, so that I can make a website for my boss to run reports against the information. If someone could show me how to write a variable to a database in a login script that would be great. Or even better modify my script to write the current outputs to a database instead of the .log file. I also need to find a way to put the month, day, year, time in their own fields to allow for better sorting. Does anyone know how to grab these specific informations? vb Code:
Moderator's Note: Syntax highlighting added by Nilpo. Last edited by Nilpo : November 19th, 2007 at 01:44 AM. |
|
#2
|
||||
|
||||
|
This can certainly be done, however, before going any further there are several things in your code that need to be fixed. I'm reworking your code now and I'll post back with explanations and your solution.
__________________
Click the image if at any point you don't like my decision.Scripting problems? Windows questions? Ask the Windows Guru! |
|
#3
|
||||
|
||||
|
To begin, you do not need to recreate the WshShell or FileSystemObject in your function. These have already been made available globally and the same objects should be reused. Also, in VBS there is no need to use the Set = Nothing method of unloading objects in a subroutine or method. Since these objects are only available within the current scope, they are automatically released when exiting a subroutine or function. Second, the Join function you are using to create a string from your array elements requires a second parameter to indicate a delimiter. If you want to push them together without separating them in the string, you should pass an empty ( "" ) string as a parameter instead. It looks to me like you're attempting to log the system's current date and time. You're using the Month function but this is only getting you part way to where you want to be. VBScript's Now function returns a string containing the current date and time. Use this instead. Next, I see you are trying to disable internal error handling by using the On Error Resume Next and On Error Goto 0 statements. You're approach is fine, however your placement is not. You are disabling error handling before you enter and IF statement, and then re-enabling it part way through. You should enable and disable at the same block level. If you disable before an IF statement, then you re-enable after. Alternatively, keep it to within the IF or ELSE block. Since your usage only excludes the production of a message box, I see no reason not to do this before and after the entire IF statement. On the same lines, you are using the Err object as a conditional device. While this is a great device for constructing statements that only execute upon successful completion of another task, your usage again is not correct... ...Remember that the Err object will be fired for EVERY script error, even those that are non-fatal and do not cause execution to stop. Since this value changes so frequently, you need to control it before polling for its value. To do this, make sure that it is cleared IMMEDIATELY before whatever line or lines you wish to monitor. The Err object provides a method for this. There is also no real purpose for using the Clear method when you are not actively monitoring the contents of the Err object. I've removed an extraneous call to this method that you had in the Else block of one of your IF statements. Finally, be careful with your use of DIM statements. These are used to create memory allocations for objects or variables. Using them inside of a function or subroutine will only make them available within their scope. Further, adding a DIM statement after an object is created will clear its contents. The use of Option Explicit further complicates the use of these statements so be careful to get them in the right place. If you're not sure, you can always put them at the very top of your script. When using Option Explicit, you also need to be sure not to miss ANY Dim statements. vb Code:
|