Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Writing to a text file. Permission Denied-Solved

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,3545
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Writing to a text file. Permission Denied-Solved
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Writing to a text file. Permission Denied-Solved - 6/27/2005 8:19:03 AM   
  D4y

 

Posts: 27
Score: 0
Joined: 4/1/2005
From:
Status: offline
Ok this script does everything that I want it to except return all the values. I know why it is not working properly but I dont know how to make it return all values and not just one.

code is below:


Option Explicit

Dim strLdapPath
Dim objConnection
Dim objChild
Dim lngTZBias
Dim objUser
Dim objPwdLastSet
Dim objShell
Dim lngBiasKey
Dim k
Dim Input
Dim objFSO
Dim objTextFile
Dim objTextStream

'=============================================================================================
'Input box for computername
Input = InputBox("Enter Ldap Path","Get Last Password Set Time")
strLdapPath = Input
If strLdapPath = "" Then
WScript.Quit
End If
'=============================================================================================
' Obtain local Time Zone bias from machine registry.
Set objShell = CreateObject("Wscript.Shell")
lngBiasKey = objShell.RegRead("HKLM\System\CurrentControlSet\Control\"_
& "TimeZoneInformation\ActiveTimeBias")
If UCase(TypeName(lngBiasKey)) = "LONG" Then
lngTZBias = lngBiasKey
ElseIf UCase(TypeName(lngBiasKey)) = "VARIANT()" Then
lngTZBias = 0
For k = 0 To UBound(lngBiasKey)
lngTZBias = lngTZBias + (lngBiasKey(k) * 256^k)
Next
End If
'=============================================================================================
'Connect to LDAP
Set objConnection = GetObject("LDAP://" & strLdapPath)
objConnection.Filter = Array("user")

For Each objChild In objConnection
Set objPwdLastSet = objChild.pwdLastSet
'=============================================================================================
'Write to Text File
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile("C:\" & strLdapPath & ".txt", True)
objTextFile.WriteLine objChild.Name & vbTab & _
Integer8Date(objPwdLastSet, lngTZBias)
objTextFile.Close
Next


Wscript.Echo "Operation Completed"

Function Integer8Date(objDate, lngBias)
'=============================================================================================
' Function to convert Integer8 (64-bit) value to a date, adjusted for local time zone bias.
Dim lngAdjust, lngDate, lngHigh, lngLow
lngAdjust = lngBias
lngHigh = objDate.HighPart
lngLow = objdate.LowPart
'=============================================================================================
' Account for error in IADslargeInteger property methods.
If lngLow < 0 Then
lngHigh = lngHigh + 1
End If
If (lngHigh = 0) And (lngLow = 0) Then
lngAdjust = 0
End If
lngDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) _
+ lngLow) / 600000000 - lngAdjust) / 1440
'=============================================================================================
' Trap error if lngDate is ridiculously huge.
On Error Resume Next
Integer8Date = CDate(lngDate)
If Err.Number <> 0 Then
On Error GoTo 0
Integer8Date = #1/1/1601#
End If
On Error GoTo 0
End Function
 
 
Post #: 1
 
 Re: Writing to a text file. Permission Denied-Solved - 6/28/2005 3:52:49 AM   
  D4y

 

Posts: 27
Score: 0
Joined: 4/1/2005
From:
Status: offline
ok I have changed it some but now i get Permission Denied on Line 50 which is
Set objTS = objFSO.OpenTextFile("C:\" & strLdapPath & ".txt", ForWriting, True)


here is the modified code:


Option Explicit

Dim strLdapPath
Dim objConnection
Dim objChild
Dim lngTZBias
Dim objUser
Dim objPwdLastSet
Dim objShell
Dim lngBiasKey
Dim k
Dim Input
Dim objFSO
Dim objTextFile
Dim objTS


'=============================================================================================
'Input box for computername
Input = InputBox("Enter Ldap Path","Get Last Password Set Time")
strLdapPath = Input
If strLdapPath = "" Then
WScript.Quit
End If
'=============================================================================================
' Obtain local Time Zone bias from machine registry.
Set objShell = CreateObject("Wscript.Shell")
lngBiasKey = objShell.RegRead("HKLM\System\CurrentControlSet\Control\"_
& "TimeZoneInformation\ActiveTimeBias")
If UCase(TypeName(lngBiasKey)) = "LONG" Then
lngTZBias = lngBiasKey
ElseIf UCase(TypeName(lngBiasKey)) = "VARIANT()" Then
lngTZBias = 0
For k = 0 To UBound(lngBiasKey)
lngTZBias = lngTZBias + (lngBiasKey(k) * 256^k)
Next
End If
'=============================================================================================
'Connect to LDAP
Set objConnection = GetObject("LDAP://" & strLdapPath)
objConnection.Filter = Array("user")

Const ForWriting = 2
For Each objChild In objConnection
Set objPwdLastSet = objChild.pwdLastSet
'=============================================================================================
'Write to Text File

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTS = objFSO.OpenTextFile("C:\" & strLdapPath & ".txt", ForWriting, True)
Next



Function Integer8Date(objDate, lngBias)
'=============================================================================================
' Function to convert Integer8 (64-bit) value to a date, adjusted for local time zone bias.
Dim lngAdjust, lngDate, lngHigh, lngLow
lngAdjust = lngBias
lngHigh = objDate.HighPart
lngLow = objdate.LowPart
'=============================================================================================
' Account for error in IADslargeInteger property methods.
If lngLow < 0 Then
lngHigh = lngHigh + 1
End If
If (lngHigh = 0) And (lngLow = 0) Then
lngAdjust = 0
End If
lngDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) _
+ lngLow) / 600000000 - lngAdjust) / 1440
'=============================================================================================
' Trap error if lngDate is ridiculously huge.
On Error Resume Next
Integer8Date = CDate(lngDate)
If Err.Number <> 0 Then
On Error GoTo 0
Integer8Date = #1/1/1601#
End If
On Error GoTo 0
End Function


For Each objChild In objConnection
objTS.WriteLine objChild.Name & vbTab & _
Integer8Date(objPwdLastSet, lngTZBias)

Next
objTS.Close

(in reply to D4y)
 
 
Post #: 2
 
 Re: Writing to a text file. Permission Denied-Solved - 6/28/2005 7:59:24 AM   
  D4y

 

Posts: 27
Score: 0
Joined: 4/1/2005
From:
Status: offline
got it.


Option Explicit

Dim strLdapPath
Dim objConnection
Dim objChild
Dim lngTZBias
Dim objUser
Dim objPwdLastSet
Dim objShell
Dim lngBiasKey
Dim k
Dim Input
Dim objFSO
Dim objTextFile
Dim objTS


'=============================================================================================
'Input box for computername
Input = InputBox("Enter Ldap Path","Get Last Password Set Time")
strLdapPath = Input
If strLdapPath = "" Then
WScript.Quit
End If
'=============================================================================================
' Obtain local Time Zone bias from machine registry.
Set objShell = CreateObject("Wscript.Shell")
lngBiasKey = objShell.RegRead("HKLM\System\CurrentControlSet\Control\"_
& "TimeZoneInformation\ActiveTimeBias")
If UCase(TypeName(lngBiasKey)) = "LONG" Then
lngTZBias = lngBiasKey
ElseIf UCase(TypeName(lngBiasKey)) = "VARIANT()" Then
lngTZBias = 0
For k = 0 To UBound(lngBiasKey)
lngTZBias = lngTZBias + (lngBiasKey(k) * 256^k)
Next
End If

'=============================================================================================
'Prepare Text File
Const ForWriting = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTS = objFSO.OpenTextFile("C:\" & strLdapPath & ".txt", ForWriting, True)

'=============================================================================================
'Connect to LDAP
Set objConnection = GetObject("LDAP://" & strLdapPath)
objConnection.Filter = Array("user")


For Each objChild In objConnection
Set objPwdLastSet = objChild.pwdLastSet
Next
'=============================================================================================
Function Integer8Date(objDate, lngBias)
'=============================================================================================
' Function to convert Integer8 (64-bit) value to a date, adjusted for local time zone bias.
Dim lngAdjust, lngDate, lngHigh, lngLow
lngAdjust = lngBias
lngHigh = objDate.HighPart
lngLow = objdate.LowPart
'=============================================================================================
' Account for error in IADslargeInteger property methods.
If lngLow < 0 Then
lngHigh = lngHigh + 1
End If
If (lngHigh = 0) And (lngLow = 0) Then
lngAdjust = 0
End If
lngDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) _
+ lngLow) / 600000000 - lngAdjust) / 1440
'=============================================================================================
' Trap error if lngDate is ridiculously huge.
On Error Resume Next
Integer8Date = CDate(lngDate)
If Err.Number <> 0 Then
On Error GoTo 0
Integer8Date = #1/1/1601#
End If
On Error GoTo 0
End Function

'=============================================================================================
'Write Info to Text File
For Each objChild In objConnection
objTS.WriteLine objChild.Name & vbTab & _
Integer8Date(objPwdLastSet, lngTZBias)

Next
objTS.Close
WScript.Echo "Finished Writing to Text File."

(in reply to D4y)
 
 
Post #: 3
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Writing to a text file. Permission Denied-Solved Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts