Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Cannot log to server share with Machine Startup Script

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Cannot log to server share with Machine Startup Script
  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 >>
 Cannot log to server share with Machine Startup Script - 9/18/2006 3:41:53 AM   
  carlsot

 

Posts: 3
Score: 0
Joined: 9/18/2006
Status: offline
I have the following script - all of it works except trying to write logfile2 to a server share.  Can anyone see what I have done wrong?  For testing purposes I have given Everyone (Full Control) and Domain Computers (Full Control) to the server share.  Any help is appreciated.

Option Explicit
' Define Variables
Dim objShell, objFSO, objSysInfo, ws, readfile, logfile, logfile2    'as Object
Dim arAddresses, tbl_contents, ip_oct 'as Array
Dim filetxt, machinename, username, installed_date, sub_line, contents, intReturn 'as Text
Dim aaa, bbb, ip, subnet, line, ip_subnet, fileserver, dist_type, file_path 'as Text
Dim strOSCapt, strSPMajor, strVersion 'as Text
' Create main objects
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FilesystemObject")
Set objSysInfo = CreateObject("ADSystemInfo")
Set ws = CreateObject("Wscript.Network")
' Main work directory
Dim TmpDir : TmpDir = objShell.Environment("Process")("Temp")
' Early check to see if installed already not done via AD
On Error Resume Next
installed_date = objShell.RegRead("HKLM\SOFTWARE\VF\Applications\.NET v2.0\Installed")
'dotnetfx
aaa = objShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{7131646D-CD3C-40F4-97B9-CD9E4E6262EF}\DisplayName")
On Error GoTo 0
'#region Exit if already installed
If IsEmpty(installed_date) And Not(IsEmpty(aaa)) Then
GetNames()
objShell.RegWrite "HKLM\SOFTWARE\VF\Applications\.NET v2.0\Installed", Now, "REG_SZ"
objShell.RegWrite "HKLM\SOFTWARE\VF\Applications\.NET v2.0\Description", ".NET v2.0 installed by user", "REG_SZ"
objShell.RegWrite "HKLM\SOFTWARE\VF\Applications\.NET v2.0\MachineName", machinename, "REG_SZ"
objShell.RegWrite "HKLM\SOFTWARE\VF\Applications\.NET v2.0\UserName", username, "REG_SZ"
' Destroy main objects
Set objShell = Nothing
Set objFSO = Nothing
Set objSysInfo = Nothing
Set ws = Nothing
' Exit
WScript.Quit(0)
ElseIf Not(IsEmpty(installed_date)) And Not(IsEmpty(aaa)) Then
' Destroy main objects
Set objShell = Nothing
Set objFSO = Nothing
Set objSysInfo = Nothing
Set ws = Nothing
' Exit
WScript.Quit(0) 
End If' #endregion
' Detect OS version
GetNames()
ListOSProperties( machinename )
If strVersion < "5.0.2195" Then WScript.Quit(0)
If strVersion = "5.0.2195" And strSPMajor < "3" Then WScript.Quit(0)
' Subnet.tbl file location
file_path = objFSO.GetParentFolderName(WScript.ScriptFullName)
'*********************************************************
' Main code entry point
'*********************************************************
' Get ipaddress of system
arAddresses = GetIPAddresses()
' Read subnet.tbl file
tbl_contents = ReadTBLFile()
' Define fileserver
For Each ip In arAddresses
' Check ip against the tbl file
ip_oct = Split(ip, ".")
If ip_oct(0) <> 9 Then
   subnet = ip_oct(0) + "." + ip_oct(1) + "." + ip_oct(2)
For Each line In tbl_contents
   If InStr(1, line, "#") = 0 Then
    sub_line = Split(line, ",")
    If sub_line(0) = subnet Then
     ' mark it
     ip_subnet = subnet
     fileserver = sub_line(1)
     dist_type = sub_line(2)
     If dist_type = "ra" Or dist_type = "ia" Then WScript.Quit(0)
     Exit For
    End If
   End If
  Next
 End If
Next
' Copy code from selected fileserver
If Not(objFSO.FileExists("\\" + fileserver + "\swdimages$\active_directory\dotnetfx.exe") And _
objFSO.FileExists("\\" + fileserver + "\swdimages$\active_directory\KB893803-v2-x86.exe") And _
objFSO.FileExists("\\" + fileserver + "\swdimages$\active_directory\NDP20-KB917283-X86.exe")) Then
WScript.Quit (0)
End If
'\\vfhq2aprint\swdimages$\active_directory
If objFSO.FileExists("\\" + fileserver + "\swdimages$\active_directory\dotnetfx.exe") Then
objFSO.CopyFile "\\" + fileserver + "\swdimages$\active_directory\dotnetfx.exe", TmpDir + "\dotnetfx.exe"
End If
'KB893803-v2-x86.exe
If objFSO.FileExists("\\" + fileserver + "\swdimages$\active_directory\KB893803-v2-x86.exe") Then
objFSO.CopyFile "\\" + fileserver + "\swdimages$\active_directory\KB893803-v2-x86.exe", TmpDir + "\KB893803-v2-x86.exe"
End If
'NDP20-KB917283-X86.exe
If objFSO.FileExists("\\" + fileserver + "\swdimages$\active_directory\NDP20-KB917283-X86.exe") Then
objFSO.CopyFile "\\" + fileserver + "\swdimages$\active_directory\NDP20-KB917283-X86.exe", TmpDir + "\NDP20-KB917283-X86.exe"
End If
' Make logfiles directory
If Not(objFSO.FolderExists(TmpDir + "\LogFiles")) Then objFSO.CreateFolder(TmpDir + "\LogFiles")
' Install
'KB893803-v2-x86.exe /quiet /norestart /overwriteoem
intReturn = objShell.Run(TmpDir + "\KB893803-v2-x86.exe /quiet /norestart /overwriteoem", 1, TRUE)
intReturn = objShell.Run(TmpDir + "\KB893803-v2-x86.exe /quiet /integrate:c:\resource", 1, TRUE)
objFSO.DeleteFile(TmpDir + "\KB893803-v2-x86.exe")
'dotnetfx.exe /q /c:"install.exe /v/qb!"
intReturn = objShell.Run(TmpDir + "\dotnetfx.exe /q:a /c:" + chr(34) + "install.exe /v/qn" + chr(34), 1, TRUE)
objFSO.DeleteFile(TmpDir + "\dotnetfx.exe")
'NDP20-KB917283-X86.exe /quiet /norestart
intReturn = objShell.Run(TmpDir + "\NDP20-KB917283-X86.exe /quiet /norestart", 1, TRUE)
objFSO.DeleteFile(TmpDir + "\NDP20-KB917283-X86.exe")
' Verify the installation has been completed
'KB893803
aaa = objShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\KB893803v2\DisplayVersion")
'dotnetfx
bbb = objShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{7131646D-CD3C-40F4-97B9-CD9E4E6262EF}\DisplayName")
If aaa <> "" And bbb <> "" Then
' Write registry key
objShell.RegWrite "HKLM\SOFTWARE\VF\Applications\.NET v2.0\Installed", Now, "REG_SZ"
objShell.RegWrite "HKLM\SOFTWARE\VF\Applications\.NET v2.0\Description", ".NET v2.0 deployed via AD", "REG_SZ"
objShell.RegWrite "HKLM\SOFTWARE\VF\Applications\.NET v2.0\FileServer", fileserver, "REG_SZ"
objShell.RegWrite "HKLM\SOFTWARE\VF\Applications\.NET v2.0\IP_Subnet", ip_subnet, "REG_SZ"
objShell.RegWrite "HKLM\SOFTWARE\VF\Applications\.NET v2.0\MachineName", machinename, "REG_SZ"
objShell.RegWrite "HKLM\SOFTWARE\VF\Applications\.NET v2.0\UserName", username, "REG_SZ"
'Log installation tasks to local system
Set logfile = objFSO.OpenTextFile(TmpDir + "\LogFiles\AD.NET_Deploy.log", 8, TRUE)
logfile.WriteLine("Installed:" + vbTab + CStr(Now))
logfile.WriteLine("Description:" + vbTab + ".NET v2.0 deployed via AD")
logfile.WriteLine("FileServer:" + vbTab + fileserver)
logfile.WriteLine("IP_Subnet:" + vbTab + ip_subnet)
logfile.WriteLine("MachineName:" + vbTab + machinename)
logfile.WriteLine("UserName:" + vbTab + username)
logfile.close
'Log installation tasks to server
Set logfile2 = objFSO.OpenTextFile("\\vfhq2atmegw01\logs\dotnetv2.0_deploy\" + machinename + ".log", 8, TRUE)
logfile2.WriteLine("Installed:" + vbTab + CStr(Now))
logfile2.WriteLine("Description:" + vbTab + ".NET v2.0 deployed via AD")
logfile2.WriteLine("FileServer:" + vbTab + fileserver)
logfile2.WriteLine("IP_Subnet:" + vbTab + ip_subnet)
logfile2.WriteLine("MachineName:" + vbTab + machinename)
logfile2.WriteLine("UserName:" + vbTab + username)
logfile2.close
End If
' Destroy main objects
Set objShell = Nothing
Set objFSO = Nothing
Set objSysInfo = Nothing
Set ws = Nothing
' Exit
WScript.Quit(0)
' Read subnet.tbl file
Function ReadTBLFile()
set readfile = objFSO.OpenTextFile(file_path + "\subnet.tbl", 1, false)
contents = Split(readfile.ReadAll, vblf)
readfile.close
ReadTBLFile = contents
End Function
' Get Machine/Usernames
Function GetNames()
machinename = ws.ComputerName
username = ws.UserName
End Function
' Get IP address
Function GetIPAddresses()
'=====
' Returns array of IP Addresses as output
' by ipconfig or winipcfg...
'
' Win98/WinNT have ipconfig (Win95 doesn't)
' Win98/Win95 have winipcfg (WinNt doesn't)
'
' Note: The PPP Adapter (Dial Up Adapter) is
' excluded if not connected (IP address will be 0.0.0.0)
' and included if it is connected.
'=====
Dim ts, sh, fso 'as Object
Dim Env 'as Text
Dim workfile, index, n 'as Text
Dim data, arIPAddress, parts 'as Array
Set sh = createobject("wscript.shell")
Set fso = createobject("scripting.filesystemobject")
Set Env = sh.Environment("PROCESS")
If Env("OS") = "Windows_NT" Then
workfile = fso.gettempname
sh.run "%comspec% /c ipconfig > " & workfile,0,True
Else
'winipcfg in batch mode sends output To
'filename winipcfg.out
workfile = "winipcfg.out"
sh.run "winipcfg /batch" ,0,True
End If
Set sh = Nothing
Set ts = fso.opentextfile(workfile)
data = Split(ts.readall,vbCr)
ts.close
Set ts = Nothing
fso.deletefile workfile
Set fso = Nothing
arIPAddress = Array()
index = -1
For n = 0 To UBound(data)
If InStr(data(n),"IP Address") Then
 parts = Split(data(n),":")
 If Trim(parts(1)) <> "0.0.0.0" Then
  index = index + 1
  ReDim Preserve arIPAddress(index)
  arIPAddress(index)= Trim(CStr(parts(1)))
 End If
End If
Next
GetIPAddresses = arIPAddress
End Function

Function ListOSProperties( strComputer )
Dim objWMIService, colItems, objItem
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem In colItems
strOSCapt = objItem.Caption
strSPMajor = objItem.ServicePackMajorVersion '4
strVersion = objItem.Version '5.0.2195 Function
Next
End Function

< Message edited by carlsot -- 9/18/2006 3:47:12 AM >
 
 
Post #: 1
 
 RE: Cannot log to server share with Machine Startup Script - 9/18/2006 4:00:37 AM   
  edavis6678

 

Posts: 122
Score: 0
Joined: 1/12/2006
Status: offline
I ran into this a long time ago, but perhaps this can help...(although not a full answer) - again, I can't remember if I got this to work and just ditched the idea and had the log files dump locally.

I seem to recall that the account that runs "start-up" scripts is the local, "SYSTEM" account.   (again..it's been a while)  See if you can add other machines "SYSTEM" account to the machine that stores the logfiles.  (I"m not sure if SYSTEM is a member of EVeryone)>

I do a very similar thing now, but I use a scheduled task, rather than a start-up script) - (But I can see how you want to do this via OU)

< Message edited by edavis6678 -- 9/18/2006 4:03:44 AM >

(in reply to carlsot)
 
 
Post #: 2
 
 RE: Cannot log to server share with Machine Startup Script - 9/18/2006 6:44:25 AM   
  carlsot

 

Posts: 3
Score: 0
Joined: 9/18/2006
Status: offline
Thanks - that does not seem to help - Any other takers? :-)

(in reply to edavis6678)
 
 
Post #: 3
 
 RE: Cannot log to server share with Machine Startup Scr... - 9/18/2006 8:35:59 AM   
  carlsot

 

Posts: 3
Score: 0
Joined: 9/18/2006
Status: offline
We have 3 domains - the server I wanted to use was not in the AD domain but one of the 3.  Even though a trust exists, it would not work.  Created  a share on a AD Domain server and worked like a charm.

Thx!

(in reply to carlsot)
 
 
Post #: 4
 
 RE: Cannot log to server share with Machine Startup Scr... - 9/18/2006 8:10:23 PM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
did you check this line
Set logfile2 = objFSO.OpenTextFile("\\vfhq2atmegw01\logs\dotnetv2.0_deploy\" + machinename + ".log", 8, TRUE)
should it not be
Set logfile2 = objFSO.OpenTextFile("\\vfhq2atmegw01\logs\dotnetv2.0_deploy" + machinename + ".log", 8, TRUE)

(in reply to carlsot)
 
 
Post #: 5
 
 
 
  

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 >> Cannot log to server share with Machine Startup Script 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