CaTBuS

Forum Replies Created

Viewing 19 posts - 1 through 19 (of 19 total)
  • Author
    Posts
  • CaTBuS
    CaTBuS
    Participant
    in reply to: Posting Issues #615616

    I resubmitted my topic and the second attempt worked. I still don’t know why my first post never showed up. The Powershell sub still showed that I had last edited it but the post was missing. Oh well. Please disregard.

    CaTBuS
    CaTBuS
    Participant
    in reply to: Remote VB Script Execution Issues #309116

    Update: I figured out my problem. The Invoke-Command is executing on the remote session as “ME” instead of the current logged on user. Is there anyway to have this code execute as the logged on user but with my credentials?

    CaTBuS
    CaTBuS
    Participant
    in reply to: VBS Script To Create AD User "Home Drive" #309115

    This should do everything you need. I’ve tested it and it works a treat. I’ve not added code to add/modify permissions for “Domain Admins” as in most environments this is already forced. If your environment is not set this way, just create another variable/command set for the AD Group. Let me know if you have any questions!

    Code:
    Option Explicit

    Dim objShell, objFSO, objNetwork, objDomain
    Dim strDomain, strUser

    Set objShell = CreateObject(“WScript.Shell”)
    Set objFSO = CreateObject(“Scripting.FileSystemObject”)
    Set objNetwork = CreateObject(“WScript.Network”)
    Set objDomain = getObject(“LDAP://rootDse”)

    ‘ DECLARE VARIABLE STRINGS
    strDomain = objDomain.Get(“dnsHostName”)
    strUser = objNetwork.UserName
    strFolder = “\FileServerUsers” & strUser

    ‘ IF NETWORK FOLDER DOES NOT EXIST, CREATE FOLDER AND SET PERMISSIONS
    If Not (objFSO.FolderExists(strFolder)) Then
    Dim strICACLS, intRunError
    Set strICACLS = “%comspec% /c echo Y|icacls ” & strFolder & ” /grant ” & strUser & “:(OI)(CI)F /inheritance:r”

    objFSO.CreateFolder(strFolder)
    intRunError = objShell.Run(strICACLS, 2, True)
    End If

    ‘ IF MAPPED DRIVE DOES NOT EXIST, CREATE MAPPED DRIVE
    If Not (objFSO.DriveExists(“Z:”)) Then
    objNetwork.MapNetworkDrive “Z:”, strFolder
    End If

    WScript.Quit

    CaTBuS
    CaTBuS
    Participant
    in reply to: Startup Script – Execute on Network only #309114
    RicklesP;n515204 wrote:
    OK then, how about looking at the Network Location Awareness state (NetworkName) to see if the machine recognizes being on your domain (the name you see if you hover over your networking icon in the system tray? You should be able to find this at HKLMCurrentControlSetServicesTcpipParameters, value ‘DhcpDomain’ or ‘Domain’ and the data should be your domain name.

    Very good idea. I’ll play with this today. Ultimately, that might be more simplified that what I came up with. And with scripting, simple is what it’s all about!!

    Code:
    ON ERROR RESUME NEXT

    Set WSHShell = CreateObject(“WScript.Shell”)
    Set WSHProcess = WSHShell.Environment(“Process”)
    Set objDomain = getObject(“LDAP://rootDse”)
    DomainString = objDomain.Get(“dnsHostName”)
    Ping = WSHShell.Run(“ping -n 1 ” & DomainString, 0, True)

    If Ping = 0 Then
    WScript.Echo “Domain Found”
    ElseIf Ping = 1 Then
    WScript.Echo “Domain Not Found. Not on Network”
    End If

    CaTBuS
    CaTBuS
    Participant
    in reply to: Startup Script – Execute on Network only #309113
    RicklesP;n515182 wrote:
    How about looking at the state of the Netlogon service? If the device can’t talk to your DCs, netlogon can’t start (I think).

    Unfortunately, the netlogon service runs automatically regardless of being connected to my domain or not.

    CaTBuS
    CaTBuS
    Participant

    I recognize this post is a few months old but here is a batch script solution for anybody interested. Hope this helps:

    Code:
    [USER=”68995″]Echo[/USER] OFF

    :: This script will check to see if the specified target is pingable else EXIT
    :: If the target is pingable, it will check for the existance (or lack thereof) of Notepad.exe else EXIT
    :: If Notepad does not reside on the target machine, it will execute the remote installation

    :BEGIN
    SET MSI=\ServerDirectoryNotepad.msi
    SET USERHOST=Target.domain.com

    PING -n 1 %USERHOST% >nul
    IF %ERRORLEVEL%==0 (
    GOTO INSTALL
    ) ELSE IF %ERRORLEVEL%==1 (
    GOTO END
    )

    :INSTALL
    IF NOT EXIST %USERHOST%C$WINDOWSsystem32notepad.exe (
    %~dp0psexec.exe %USERHOST% -h -u domainusername -p password msiexec.exe -i %MSI%
    GOTO END
    )

    :END
    EXIT

    CaTBuS
    CaTBuS
    Participant
    in reply to: adfs for new company name #391670

    It is about ADFS. I just want to change the usernames of all users to [email protected] from [email protected] so that they can authenticate with adfs for single sign on.

    CaTBuS
    CaTBuS
    Participant

    I can confirm that there have been no patches applied, UAC changes, and no GPO changes. These particular servers are in a managed group and get no updates deployed without being selected by me. Having said that, our InfoSec group is notorious for operating like the KGB and on more than one occasion have been caught “messing around” without submitting proper change requests.

    As for user accounts, I’m using a logon-able service account with local admin rights. I’ve also tried using a standard service account with the same local admin access as well as just local system account. No account can even open notepad via task scheduler.

    CaTBuS
    CaTBuS
    Participant

    JeremyW, I just say your reply. I will try this out, hopefully this will remedy some buggy behavior I’ve been trying to fix. Thanks!

    CaTBuS
    CaTBuS
    Participant

    I have worked this out myself. Here is what I came up with:

    Code:
    ### SET FOLDER TO WATCH + FILES TO WATCH + SUBFOLDERS YES/NO
    $watcher = New-Object System.IO.FileSystemWatcher
    $watcher.Path = “C:TEMPtest”
    $watcher.Filter = “*.*”
    $watcher.IncludeSubdirectories = $false
    $watcher.EnableRaisingEvents = $true

    ### DEFINE ACTIONS AFTER A EVENT IS DETECTED
    $action = { Get-ChildItem C:TEMPtest*.txt | Move-Item -Destination C:TEMPtestArchive
    Get-ChildItem C:TEMPtestArchive*.txt | Foreach {Rename-Item -Path $_.Fullname -newname “$($_.DirectoryName)$($_.BaseName) $(get-date -format [email protected])$($_.extension)”}
    }
    ### DECIDE WHICH EVENTS SHOULD BE WATCHED + SET CHECK FREQUENCY
    $created = Register-ObjectEvent $watcher “Created” -Action $action
    while ($true) {sleep 10}

    While this code does work, it is buggy. The renaming process is greatly effected by “when” the file is created. During my testing, I got some pretty weird file names. Some had the date/time stamp 2 or 3 times in one file name. Other files had the “basename” disregarded and were renamed “New Text File.” Although this was a fun endeavor, I think I need to completely rethink this.

    CaTBuS
    CaTBuS
    Participant
    in reply to: VBS – CreateFolder with sub-dir’s (recursion) #309108

    Re: VBS – CreateFolder with sub-dir’s (recursion)

    I will work on an issue for days before posting, and without fail, I will find something minutes after I post. Anyway, I found this little gem and it does work. Having said that, it seems way to verbose. There has to be a cleaner shorter way to do this.

    Code:
    Set oShell = CreateObject(“WScript.Shell”)
    oSYSDRIV = oShell.Environment(“Volatile”).Item (“SYSTEMDRIVE”)
    WOPM = oSYSDRIV & “PrometheusWOPM”

    ‘// a normal function
    Call CreateDirectoryPath(WOPM)

    ‘// a recursion function
    Call Recursion(WOPM)

    Function CreateDirectoryPath(DirPath)

    Set objFSO = CreateObject(“Scripting.FileSystemObject”)
    If objFSO.FolderExists(DirPath) Then
    Exit Function
    End If

    aDirectories = Split(DirPath, “”)
    sCreateDirectory = aDirectories(0)
    For iDirectory = 1 To UBound(aDirectories)
    sCreateDirectory = sCreateDirectory & “” & aDirectories(iDirectory)
    If Not objFSO.FolderExists(sCreateDirectory) Then
    objFSO.CreateFolder(sCreateDirectory)
    End If
    Next
    End Function

    Function Recursion(DirectoryPath)
    Set objFSO = CreateObject(“Scripting.FileSystemObject”)

    If objFSO.FolderExists(DirectoryPath) Then Exit Function
    Call Recursion(objFSO.GetParentFolderName(DirectoryPath))
    objFSO.CreateFolder(DirectoryPath)
    End Function

    CaTBuS
    CaTBuS
    Participant
    in reply to: Find & Replace script – Expanded #309107

    Re: Find & Replace script – Expanded

    All right!! I got the whole thing working nicely for anybody who is interested. This vbscript will determin the OS then perform a Find/Replace on an OS specific file. This will be implimented for our SAPLogon.ini file which is in different locations depending on which OS you are using. Anyway, here is the code:

    Code:
    [COLOR=”Blue”]On Error Resume Next[/COLOR]

    [COLOR=”blue”]Const[/COLOR] ForReading = [COLOR=”Red”]1[/COLOR]
    [COLOR=”blue”]Const[/COLOR] ForWriting = [COLOR=”red”]2[/COLOR]

    [COLOR=”blue”]Set[/COLOR] objFSO = CreateObject(“[COLOR=”Gray”]Scripting.FileSystemObject[/COLOR]”)
    [COLOR=”blue”]Set[/COLOR] objFileXP = objFSO.OpenTextFile(“[COLOR=”gray”]C:ScriptsTestXP.txt[/COLOR]”, ForReading)
    [COLOR=”blue”]Set[/COLOR] objFile7 = objFSO.OpenTextFile(“[COLOR=”gray”]C:ScriptsTest7.txt[/COLOR]”, ForReading)

    strComputer = “.”
    [COLOR=”blue”]Set[/COLOR] objWMIService = GetObject(“[COLOR=”gray”]winmgmts:\[/COLOR]” & strComputer & “[COLOR=”gray”]rootcimv2[/COLOR]”)

    [COLOR=”blue”]Set[/COLOR] colOperatingSystems = objWMIService.ExecQuery _
    (“[COLOR=”gray”]Select * from Win32_OperatingSystem[/COLOR]”)

    [COLOR=”blue”]For Each[/COLOR] objOperatingSystem [COLOR=”blue”]in[/COLOR] colOperatingSystems

    msg = objOperatingSystem.Caption & ” ” & _
    objOperatingSystem.Version

    [COLOR=”blue”]If[/COLOR] InStr(msg, “[COLOR=”gray”]XP[/COLOR]”) [COLOR=”blue”]Then[/COLOR]
    strText = objFileXP.ReadAll
    objFileXP.Close
    strText = Replace(strText, “[COLOR=”gray”]XXX[/COLOR]”, “[COLOR=”gray”]Windows XP[/COLOR]”)

    [COLOR=”blue”]Set[/COLOR] objFileXP = objFSO.OpenTextFile(“[COLOR=”gray”]C:ScriptsTestXP.txt[/COLOR]”, ForWriting)
    objFileXP.WriteLine strText
    objFileXP.Close
    [COLOR=”blue”]ElseIf[/COLOR] InStr(msg, “[COLOR=”gray”]Windows 7[/COLOR]”) [COLOR=”blue”]Then[/COLOR]
    strText = objFile7.ReadAll
    objFile7.Close
    strText = Replace(strText, “[COLOR=”gray”]XXX[/COLOR]”, “[COLOR=”gray”]Windows 7[/COLOR]”)

    [COLOR=”blue”]Set[/COLOR] objFile7 = objFSO.OpenTextFile(“[COLOR=”gray”]C:ScriptsTest7.txt[/COLOR]”, ForWriting)
    objFile7.WriteLine strText
    objFile7.Close
    [COLOR=”blue”]End If[/COLOR]

    [COLOR=”blue”]Next[/COLOR]

    CaTBuS
    CaTBuS
    Participant
    in reply to: Find & Replace script – Expanded #309106

    Re: Find & Replace script – Expanded

    I figured out an answer to my own question. Here is what I have now:

    Code:
    [COLOR=”Blue”]Const[/COLOR] ForReading = [COLOR=”Red”]1[/COLOR]
    [COLOR=”blue”]Const[/COLOR] ForWriting = [COLOR=”red”]2[/COLOR]

    [COLOR=”blue”]Set[/COLOR] objFSO = CreateObject(“[COLOR=”Gray”]Scripting.FileSystemObject[/COLOR]”)
    [COLOR=”blue”]Set[/COLOR] objFile = objFSO.OpenTextFile(“[COLOR=”gray”]C:ScriptsTest.txt[/COLOR]”, ForReading)

    strText = objFile.ReadAll
    objFile.Close
    strNewText1 = Replace(strText, “[COLOR=”gray”]server1.location1″, “server1[/COLOR]”)
    strNewText2 = Replace(strNewText1, “[COLOR=”gray”]server2.location2″, “server2[/COLOR]”)

    [COLOR=”blue”]Set[/COLOR] objFile = objFSO.OpenTextFile(“[COLOR=”gray”]C:ScriptsTest.txt[/COLOR]”, ForWriting)
    objFile.WriteLine strNewText2
    objFile.Close

    Depending on the OS version (XP or Win7), this file will be located in a different location. What I need to do now is check the OS version, if XP, execute above code for one location, If Win7, execute code for other location. I found the below code to check OS. I now need to figure out how to combine the two:

    Code:
    strComputer = “.”

    Set objWMIService = GetObject(“winmgmts:\” & strComputer & “rootcimv2”)
    Set colOperatingSystems = objWMIService.ExecQuery (“Select * from Win32_OperatingSystem”)

    For Each objOperatingSystem in colOperatingSystems

    msg = objOperatingSystem.Caption & ” ” & objOperatingSystem.Version
    msgbox msg
    Next

    CaTBuS
    CaTBuS
    Participant
    in reply to: VB Script to modify tnsnames.ora file #309105

    Re: VB Script to modify tnsnames.ora file

    Thanks rems! No surprise, your code worked perfectly. I actually found the carriage line feed command and added it as a new line of code. I think my finished product is a good as can be thanks to you. I owe you a beer.:beer:

    CaTBuS
    CaTBuS
    Participant
    in reply to: VB Script to modify tnsnames.ora file #309104

    Re: VB Script to modify tnsnames.ora file

    This is great. I have been playing with this and it will most certainly work. My only question is that this needs to write multiple lines of code in succession. The carriage returns are causing errors. Do I need to create a new object for each line of text? Or is there syntax for multiple lines for one object? Here is a sample of the code:

    strNewLine = “ts1db.world=
    (DESCRIPTION =
    (ADDRESS LIST =
    COMMUNIY = sap.world (and so on and so forth)”

    Thanks again.

    CaTBuS
    CaTBuS
    Participant
    in reply to: Script for timed keystrokes in an active program #309103

    Re: Script for timed keystrokes in an active program

    Thanks guys. Lior_S, I ended up using an app much like the one you suggested but made specifically for games called ACTool. It worked like a charm and have been using it successfully for my gaming needs.

    REMS, genius as always. Although the ACTool is fitting the bill, I am going to use your suggestions anyway as it always furthers my scripting know-how. You guys rock and so does this site.

    CaTBuS
    CaTBuS
    Participant
    in reply to: Batch file 2 remap network drive 2 another letter #309102

    Re: Batch file 2 remap network drive 2 another letter

    Thank you again REMS. I have already tested the new sc and am going to roll out our sms package to our test group today.

    This script has been tested successfully in Windows XP Pro and Vista Ultimate environments. All contingencies of drive states were tested.

    I am pulling my VB book out of the case after today. REMS has inspired me. On another note, I am posting another thread that will hopefully add to this script. I am currently using a GPO edit to then hide the below G: drive. Although the application needs full access to this mapped drive, I don’t want the users browsing to the unc path and doing damage.

    CaTBuS
    CaTBuS
    Participant
    in reply to: Batch file 2 remap network drive 2 another letter #309101

    Re: Batch file 2 remap network drive 2 another letter

    That modification doesn’t seem to change anything. The only thing that I could possibly find wrong with this script is that if there is no G: initially, nothing happens. By this I mean no G: is created. However, if G: is currently mapped elsewhere, then it is reassigned to the next available drive letter and then G: is created properly.

    I think this is what you were getting at with the modification from your last post, I just wanted to clarify.

    CaTBuS
    CaTBuS
    Participant
    in reply to: Batch file 2 remap network drive 2 another letter #309100

    Re: Batch file 2 remap network drive 2 another letter

    REMS, this is perfect. You are a GOD!! Thank you so much for your time and effort.

Viewing 19 posts - 1 through 19 (of 19 total)