aslandk
asked on
change kix script to vbs script
Hello there
I have a small script written in kix syntax. Is it possible to write it in vbs scritpt instead?
Here is the script:
IF INGROUP("administrator")
$Result = CompareFileTimes("\\server \folder\te st.ini", "d:\winnt\test.ini")
If $Result = 1 or $Result = -3
copy \\server\administrator\tes t.ini d:\winnt
Endif
ENDIF
I hope someone can help me:)
I have a small script written in kix syntax. Is it possible to write it in vbs scritpt instead?
Here is the script:
IF INGROUP("administrator")
$Result = CompareFileTimes("\\server
If $Result = 1 or $Result = -3
copy \\server\administrator\tes
Endif
ENDIF
I hope someone can help me:)
ASKER
looks like something i can use:):)
something like this:
If MemberOf(ObjGroupDict, "domain admins") Then
but what about the rest of the script...dont know anything about kix(:
agj << Can you help??
something like this:
If MemberOf(ObjGroupDict, "domain admins") Then
but what about the rest of the script...dont know anything about kix(:
agj << Can you help??
The copy file code:
Dim FSO
Dim mFile1
Dim mFile2
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
Set mFile1 = fso.GetFile("\\server\fold er\test.in i")
If fso.FileExists("d:\winnt\t est.ini") then
Set mFile2 = fso.GetFile("d:\winnt\test .ini")
If mFile1.DateLastModified > mFile2.DateLastModified Then
fso.CopyFile "\\server\administrator\te st.ini", "d:\winnt\test.ini", True
end if
else
fso.CopyFile "\\server\administrator\te st.ini", "d:\winnt\test.ini", True
end if
Dim FSO
Dim mFile1
Dim mFile2
Set fso = CreateObject("Scripting.Fi
Set mFile1 = fso.GetFile("\\server\fold
If fso.FileExists("d:\winnt\t
Set mFile2 = fso.GetFile("d:\winnt\test
If mFile1.DateLastModified > mFile2.DateLastModified Then
fso.CopyFile "\\server\administrator\te
end if
else
fso.CopyFile "\\server\administrator\te
end if
Dim WSHNetwork
Dim strUserName ' Current user
Dim strUserDomain ' Current User's domain name
Dim ObjGroupDict ' Dictionary of groups to which the user belongs
Set WSHNetwork = WScript.CreateObject("WScr ipt.Networ k")
strUserName = WSHNetwork.UserName
strUserDomain = WSHNetwork.UserDomain
' Read the user's account "Member Of" tab info across the network
' once into a dictionary object.
Set ObjGroupDict = CreateMemberOfObject(strUs erDomain, strUserName)
If MemberOf(ObjGroupDict, "Administrators") Then 'use the relevant group name
'the copy file code here...
End If
Dim strUserName ' Current user
Dim strUserDomain ' Current User's domain name
Dim ObjGroupDict ' Dictionary of groups to which the user belongs
Set WSHNetwork = WScript.CreateObject("WScr
strUserName = WSHNetwork.UserName
strUserDomain = WSHNetwork.UserDomain
' Read the user's account "Member Of" tab info across the network
' once into a dictionary object.
Set ObjGroupDict = CreateMemberOfObject(strUs
If MemberOf(ObjGroupDict, "Administrators") Then 'use the relevant group name
'the copy file code here...
End If
ASKER
thanks.....:):)
Just to check if i have understand you correct:
$Result = CompareFileTimes("\\server \folder\te st.ini", "d:\winnt\test.ini")
equal to
If mFile1.DateLastModified > mFile2.DateLastModified Then
The DateLastModified function only checks the datetime?
so the full convertion to vbs script would be:
If MemberOf(ObjGroupDict, "Domain Admins") Then
Dim FSO
Dim mFile1
Dim mFile2
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
Set mFile1 = fso.GetFile("\\server\fold er\test.in i")
If fso.FileExists("d:\winnt\t est.ini") then
Set mFile2 = fso.GetFile("d:\winnt\test .ini")
If mFile1.DateLastModified > mFile2.DateLastModified Then
fso.CopyFile "\\server\administrator\te st.ini", "d:\winnt\test.ini", True
end if
else
fso.CopyFile "\\server\administrator\te st.ini", "d:\winnt\test.ini", True
end if
One last question:
the condition:
If $Result = 1 or $Result = -3
has and "or" parameter but in the script you wrote you only used > "If mFile1.DateLastModified > mFile2.DateLastModified Then"
Is that the same?
I know I have asked you a lot of question but you seems like you know what you are talking about:):)
You have been a GREAT help so far:)
Just to check if i have understand you correct:
$Result = CompareFileTimes("\\server
equal to
If mFile1.DateLastModified > mFile2.DateLastModified Then
The DateLastModified function only checks the datetime?
so the full convertion to vbs script would be:
If MemberOf(ObjGroupDict, "Domain Admins") Then
Dim FSO
Dim mFile1
Dim mFile2
Set fso = CreateObject("Scripting.Fi
Set mFile1 = fso.GetFile("\\server\fold
If fso.FileExists("d:\winnt\t
Set mFile2 = fso.GetFile("d:\winnt\test
If mFile1.DateLastModified > mFile2.DateLastModified Then
fso.CopyFile "\\server\administrator\te
end if
else
fso.CopyFile "\\server\administrator\te
end if
One last question:
the condition:
If $Result = 1 or $Result = -3
has and "or" parameter but in the script you wrote you only used > "If mFile1.DateLastModified > mFile2.DateLastModified Then"
Is that the same?
I know I have asked you a lot of question but you seems like you know what you are talking about:):)
You have been a GREAT help so far:)
-3 is the return code for 2nd file not existing and 1 for first file newer...
-3 is taken care by the FileExists things
1 by checking DateModified....
simply using isgroup wont work...use the code i jus sent
-3 is taken care by the FileExists things
1 by checking DateModified....
simply using isgroup wont work...use the code i jus sent
Dim WSHNetwork
Dim strUserName ' Current user
Dim strUserDomain ' Current User's domain name
Dim ObjGroupDict ' Dictionary of groups to which the user belongs
Set WSHNetwork = WScript.CreateObject("WScr ipt.Networ k")
strUserName = WSHNetwork.UserName
strUserDomain = WSHNetwork.UserDomain
' Read the user's account "Member Of" tab info across the network
' once into a dictionary object.
Set ObjGroupDict = CreateMemberOfObject(strUs erDomain, strUserName)
If MemberOf(ObjGroupDict, "Administrators") Then 'use the relevant group name
'the copy file code here...
Dim FSO
Dim mFile1
Dim mFile2
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
Set mFile1 = fso.GetFile("\\server\fold er\test.in i")
If fso.FileExists("d:\winnt\t est.ini") then
Set mFile2 = fso.GetFile("d:\winnt\test .ini")
If mFile1.DateLastModified > mFile2.DateLastModified Then
fso.CopyFile "\\server\administrator\te st.ini", "d:\winnt\test.ini", True
end if
else
fso.CopyFile "\\server\administrator\te st.ini", "d:\winnt\test.ini", True
end if
'Copy file code ends
End If
Dim strUserName ' Current user
Dim strUserDomain ' Current User's domain name
Dim ObjGroupDict ' Dictionary of groups to which the user belongs
Set WSHNetwork = WScript.CreateObject("WScr
strUserName = WSHNetwork.UserName
strUserDomain = WSHNetwork.UserDomain
' Read the user's account "Member Of" tab info across the network
' once into a dictionary object.
Set ObjGroupDict = CreateMemberOfObject(strUs
If MemberOf(ObjGroupDict, "Administrators") Then 'use the relevant group name
'the copy file code here...
Dim FSO
Dim mFile1
Dim mFile2
Set fso = CreateObject("Scripting.Fi
Set mFile1 = fso.GetFile("\\server\fold
If fso.FileExists("d:\winnt\t
Set mFile2 = fso.GetFile("d:\winnt\test
If mFile1.DateLastModified > mFile2.DateLastModified Then
fso.CopyFile "\\server\administrator\te
end if
else
fso.CopyFile "\\server\administrator\te
end if
'Copy file code ends
End If
the above post is jus the consolidated code incase u found the prev. unclear...
i guess u shud put the group as "administrator" and not Administrators as I put, since ur kix script seems to be so...
i guess u shud put the group as "administrator" and not Administrators as I put, since ur kix script seems to be so...
ASKER
testing your "gold script":):)......will respond soon.....but thanks so far
ASKER
it seems to ork fine...but i have a question about the if/else statement:
If mFile1.DateLastModified > mFile2.DateLastModified Then
fso.CopyFile "\\server\administrator\te st.ini", "d:\winnt\test.ini", True
end if
else
fso.CopyFile "\\server\administrator\te st.ini", "d:\winnt\test.ini", True
end if
looks like the script do the same no matter if the "if" or "else" condition is true....am i wrong?
If mFile1.DateLastModified > mFile2.DateLastModified Then
fso.CopyFile "\\server\administrator\te
end if
else
fso.CopyFile "\\server\administrator\te
end if
looks like the script do the same no matter if the "if" or "else" condition is true....am i wrong?
u have missed the earlier:
If fso.FileExists("d:\winnt\t est.ini") then
which is the corresponding If for the Else statement
If fso.FileExists("d:\winnt\t
which is the corresponding If for the Else statement
the logic is:
if "file 2 exists" then
if file 1 is newer then
copy file
end if
else
copy anyways
end if
if "file 2 exists" then
if file 1 is newer then
copy file
end if
else
copy anyways
end if
ASKER
ahhh i can see what you mean..:):)
I have about 10 of the same if statements:
If MemberOf(ObjGroupDict, "Administrators") Then 'use the relevant group name
just with different groupnames of course. Is there a smarter way to optimize the script or do i hvae to make 10 if statement almost the same?
I have about 10 of the same if statements:
If MemberOf(ObjGroupDict, "Administrators") Then 'use the relevant group name
just with different groupnames of course. Is there a smarter way to optimize the script or do i hvae to make 10 if statement almost the same?
ASKER
for eksample:
the Domain Admins looks like this:
If MemberOf(ObjGroupDict, "Domain Admins") Then 'use the relevant group name
'the copy file code here...
Dim FSO
Dim mFile1
Dim mFile2
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
Set mFile1 = fso.GetFile("\\server\doma inadmin\te st.ini")
If fso.FileExists("d:\winnt\t est.ini") then
Set mFile2 = fso.GetFile("d:\winnt\test .ini")
If mFile1.DateLastModified > mFile2.DateLastModified Then
fso.CopyFile "\\server\domainadmin\test .ini", "d:\winnt\test.ini", True
end if
else
fso.CopyFile "\\server\domainadmin\test .ini", "d:\winnt\test.ini", True
end if
'Copy file code ends
End If
the power userlooks like this:
If MemberOf(ObjGroupDict, "Power User") Then 'use the relevant group name
'the copy file code here...
Dim FSO
Dim mFile1
Dim mFile2
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
Set mFile1 = fso.GetFile("\\server\powe ruser\test .ini")
If fso.FileExists("d:\winnt\t est.ini") then
Set mFile2 = fso.GetFile("d:\winnt\test .ini")
If mFile1.DateLastModified > mFile2.DateLastModified Then
fso.CopyFile "\\server\poweruser\test.i ni", "d:\winnt\test.ini", True
end if
else
fso.CopyFile "\\server\poweruser\test.i ni", "d:\winnt\test.ini", True
end if
'Copy file code ends
End If
as you can se the only thing that is different is the group name and the directory to copy the file to and from.
the Domain Admins looks like this:
If MemberOf(ObjGroupDict, "Domain Admins") Then 'use the relevant group name
'the copy file code here...
Dim FSO
Dim mFile1
Dim mFile2
Set fso = CreateObject("Scripting.Fi
Set mFile1 = fso.GetFile("\\server\doma
If fso.FileExists("d:\winnt\t
Set mFile2 = fso.GetFile("d:\winnt\test
If mFile1.DateLastModified > mFile2.DateLastModified Then
fso.CopyFile "\\server\domainadmin\test
end if
else
fso.CopyFile "\\server\domainadmin\test
end if
'Copy file code ends
End If
the power userlooks like this:
If MemberOf(ObjGroupDict, "Power User") Then 'use the relevant group name
'the copy file code here...
Dim FSO
Dim mFile1
Dim mFile2
Set fso = CreateObject("Scripting.Fi
Set mFile1 = fso.GetFile("\\server\powe
If fso.FileExists("d:\winnt\t
Set mFile2 = fso.GetFile("d:\winnt\test
If mFile1.DateLastModified > mFile2.DateLastModified Then
fso.CopyFile "\\server\poweruser\test.i
end if
else
fso.CopyFile "\\server\poweruser\test.i
end if
'Copy file code ends
End If
as you can se the only thing that is different is the group name and the directory to copy the file to and from.
u can create a procedure which takes the group as parameter and runs its all.
here's a sample:
DoStuff("admin")
DoStuff("normal user")
DoStuff("domain user")
function DoStuff(param1)
msgbox param1
'write your code out here with param1 as parameter.
end function
DoStuff("admin")
DoStuff("normal user")
DoStuff("domain user")
function DoStuff(param1)
msgbox param1
'write your code out here with param1 as parameter.
end function
Dostuff("Domain Admins", "domainadmin")
Dostuff("Power User", "poweruser")
Function Dostuff(GrpName, Directory)
Dim WSHNetwork
Dim strUserName ' Current user
Dim strUserDomain ' Current User's domain name
Dim ObjGroupDict ' Dictionary of groups to which the user belongs
Set WSHNetwork = WScript.CreateObject("WScr ipt.Networ k")
strUserName = WSHNetwork.UserName
strUserDomain = WSHNetwork.UserDomain
' Read the user's account "Member Of" tab info across the network
' once into a dictionary object.
Set ObjGroupDict = CreateMemberOfObject(strUs erDomain, strUserName)
If MemberOf(ObjGroupDict, GrpName) Then 'use the relevant group name
'the copy file code here...
Dim FSO
Dim mFile1
Dim mFile2
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
Set mFile1 = fso.GetFile("\\server\" & Directory & "\test.ini")
If fso.FileExists("d:\winnt\t est.ini") then
Set mFile2 = fso.GetFile("d:\winnt\test .ini")
If mFile1.DateLastModified > mFile2.DateLastModified Then
fso.CopyFile "\\server\" & Directory & "\test.ini", "d:\winnt\test.ini", True
end if
else
fso.CopyFile "\\server\" & Directory & "\test.ini", "d:\winnt\test.ini", True
end if
'Copy file code ends
End If
End Function
Dostuff("Power User", "poweruser")
Function Dostuff(GrpName, Directory)
Dim WSHNetwork
Dim strUserName ' Current user
Dim strUserDomain ' Current User's domain name
Dim ObjGroupDict ' Dictionary of groups to which the user belongs
Set WSHNetwork = WScript.CreateObject("WScr
strUserName = WSHNetwork.UserName
strUserDomain = WSHNetwork.UserDomain
' Read the user's account "Member Of" tab info across the network
' once into a dictionary object.
Set ObjGroupDict = CreateMemberOfObject(strUs
If MemberOf(ObjGroupDict, GrpName) Then 'use the relevant group name
'the copy file code here...
Dim FSO
Dim mFile1
Dim mFile2
Set fso = CreateObject("Scripting.Fi
Set mFile1 = fso.GetFile("\\server\" & Directory & "\test.ini")
If fso.FileExists("d:\winnt\t
Set mFile2 = fso.GetFile("d:\winnt\test
If mFile1.DateLastModified > mFile2.DateLastModified Then
fso.CopyFile "\\server\" & Directory & "\test.ini", "d:\winnt\test.ini", True
end if
else
fso.CopyFile "\\server\" & Directory & "\test.ini", "d:\winnt\test.ini", True
end if
'Copy file code ends
End If
End Function
ASKER
looks good....
I have worked on the syntax myself....:
Dim path
Dim file
Dim folder
Dim foldername
path = "\\server\c$"
file = "test.txt"
folder = "testfolder"
If MemberOf(ObjGroupDict, "Domain Admins") Then
foldername = "Domain Admins"
Dim mFile1
Dim mFile2
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
Set mFile1 = fso.GetFile(path & "\" & foldername & "\" & file)
If fso.FileExists(path & "\" & folder & "\" & file) then
Set mFile2 = fso.GetFile(path & "\" & folder & "\" & file)
If mFile1.DateLastModified > mFile2.DateLastModified Then
fso.CopyFile path & "\" & foldername & "\" & file, path & "\" & folder & "\" , True
end if
else
fso.CopyFile path & "\" & foldername & "\" & file, path & "\" & folder & "\" , True
end if
End If
But in my example i need and if statement for each group....can i make it smarter?
Is your example better than mine?
I have worked on the syntax myself....:
Dim path
Dim file
Dim folder
Dim foldername
path = "\\server\c$"
file = "test.txt"
folder = "testfolder"
If MemberOf(ObjGroupDict, "Domain Admins") Then
foldername = "Domain Admins"
Dim mFile1
Dim mFile2
Set fso = CreateObject("Scripting.Fi
Set mFile1 = fso.GetFile(path & "\" & foldername & "\" & file)
If fso.FileExists(path & "\" & folder & "\" & file) then
Set mFile2 = fso.GetFile(path & "\" & folder & "\" & file)
If mFile1.DateLastModified > mFile2.DateLastModified Then
fso.CopyFile path & "\" & foldername & "\" & file, path & "\" & folder & "\" , True
end if
else
fso.CopyFile path & "\" & foldername & "\" & file, path & "\" & folder & "\" , True
end if
End If
But in my example i need and if statement for each group....can i make it smarter?
Is your example better than mine?
ya...i think my example makes it easier...
ASKER
but where do you define the diffirent folders/directories in your script?
Function Dostuff(GrpName, Directory)
the second arg is the directory name (the part of the directory name that changes)
the second arg is the directory name (the part of the directory name that changes)
ASKER
but how do you declare the foldernames?
I did ilike this:
If MemberOf(ObjGroupDict, "Domain Admins") Then
foldername = "Domain Admins"
I did ilike this:
If MemberOf(ObjGroupDict, "Domain Admins") Then
foldername = "Domain Admins"
i think its quite clear in teh code...
Dostuff("Domain Admins", "domainadmin") 'the SECOND PARAM is used to construct the directory name
Dostuff("Power User", "poweruser")
the functioon definition was:
Function Dostuff(GrpName, Directory)
the following line has the Directory parameter used.
Set mFile1 = fso.GetFile("\\server\" & Directory & "\test.ini")
if u feel like it use ur method itself....
Dostuff("Domain Admins", "domainadmin") 'the SECOND PARAM is used to construct the directory name
Dostuff("Power User", "poweruser")
the functioon definition was:
Function Dostuff(GrpName, Directory)
the following line has the Directory parameter used.
Set mFile1 = fso.GetFile("\\server\" & Directory & "\test.ini")
if u feel like it use ur method itself....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
sorry....has been on weekend and away from computer...thanks for your help:):)
http://hacks.oreilly.com/pub/h/1130