Rems

Forum Replies Created

Viewing 30 posts - 1 through 30 (of 2,323 total)
  • Author
    Posts
  • Avatar
    Rems
    Moderator
    in reply to: Filtering Findstr results #228480

    For /F “tokens=*” %%a in (‘findstr /i %1 x:itlogswho_when.txt ^| findstr /i %2’) do for %%b in (%%a) do set machine=%%b
    SCCM RemoteControl %machine%[/CODE][CODE]For /F “tokens=*” %%a in (‘findstr /i %1 x:itlogswho_when.txt ^| findstr /i %2’) do for %%b in (%%a) do set machine=%%b
    SCCM RemoteControl %machine%[/CODE]

    Avatar
    Rems
    Moderator

    Hi,

    Both batch scripts in your post should work. They are working well on my computer.

    In the script below I just added goto:EOF before the sub routines (this could be the cause that the status of the last service was only in the output). And ensured that no unnecessary spaces were added to variables. Also make sure the last value of sState is cleared before checking the next service in case a service could not be found.

    @ ECHO OFF
    SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

    SET hName=Server_1

    SET “sName[0]=Service_1”
    SET “sName[1]=Service_2”
    SET “sName[2]=Service_3”
    SET “sName[3]=Service_4”

    FOR /F “tokens=2 delims==” %%s in (‘set sName[‘) DO (
    SET “tName=%%s”
    SET “sState=” clear previous value
    CALL :SvcState
    ECHO !tName! Service is !sState!
    )

    PAUSE

    [B]endlocal & goto:EOF ————–[/B]
    :SvcState
    FOR /F “tokens=3 delims=: ” %%a in (
    ‘SC.exe \%hName% query “%tName%” ^| FINDSTR /ic:” state “‘
    ) DO (
    SET “sState=%%a”
    )
    EXIT /B
    [/CODE][CODE]
    @ ECHO OFF
    SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

    SET hName=Server_1

    SET “sName[0]=Service_1”
    SET “sName[1]=Service_2”
    SET “sName[2]=Service_3”
    SET “sName[3]=Service_4”

    FOR /F “tokens=2 delims==” %%s in (‘set sName[‘) DO (
    SET “tName=%%s”
    SET “sState=” clear previous value
    CALL :SvcState
    ECHO !tName! Service is !sState!
    )

    PAUSE

    endlocal & goto:EOF



    :SvcState
    FOR /F “tokens=3 delims=: ” %%a in (
    ‘SC.exe \%hName% query “%tName%” ^| FINDSTR /ic:” state “‘
    ) DO (
    SET “sState=%%a”
    )
    EXIT /B
    [/CODE]

    Avatar
    Rems
    Moderator
    in reply to: RPC Unavailable #228478

    You should be able to start the RPC service remotely via Computer Management > Connect to another computer … > Services
    But if you get the ‘RPC Server Unavailable’ Error this can caused by,​​​​​​

    Avatar
    Rems
    Moderator

    The batch is waiting for the exit code, therefore it wait for it to terminate. If you don’t want the batch to wait use the START command.

    @start “” “C:Testtest.txt”
    !!! mind the quotes before the path. The START command assumes that the first text between quotes in the command line is the TITLE, so if the path is between quotes you’ll have to add text between quotes to the command line before the path.

    Avatar
    Rems
    Moderator
    in reply to: Automate get-pendingrequest pki #228476
    Ryzilla44;n510419 wrote:
    Hi Guys

    I am having some issues trying to get a script working that will check my CA for any pending requests, i’m using a pki module that can do this for me.

    Get-PendingRequest CA1,CA2

    Now if i try and get that to email me when script is run i get a empty email.

    Send-Email.ps1 -To “[email protected]” -Subject “Pending Rewquest” -Body (Get-PendingRequest CA1,CA2)

    Any ideas would be awesome

    The answer provided by JeremyW should work >> $body = Get-PendingRequest CA1,CA2 | Out-String
    The pipeline operator (|) sends the content to Out-String, this returns the output as a string for the -Body argument

    You can also,

    Code:
    Send-Email.ps1 -To “[email protected]” -Subject “Pending Rewquest” -Body (Get-PendingRequest CA1,CA2 | out-string)

    or,

    Code:
    powershell.exe -executionpolicy bypass -File Send-Email.ps1 -To “[email protected]” -Subject “Pending Rewquest” -Body (Get-PendingRequest CA1,CA2 | out-string)

    The command lines above should of course be launched from a powershell prompt.

    If the default command-line interpreter of Windows (cmd .exe) is used then the command line in total should be like,

    Code:
    powershell.exe -executionpolicy bypass “& {powershell.exe -File Send-Email.ps1 -To “[email protected]” -Subject “Pending Rewquest” -Body (Get-PendingRequest CA1,CA2 | out-string)}”
    Avatar
    Rems
    Moderator
    jason0923;n509183 wrote:
    I was looking at that today but aren;t I going to run into the same problem? If the PS script is run from a Sheduled task run as the system account would the user even see the PS MSgBox?

    Yup the dialog box will also popup from a scheduled task.

    Scheduled Task > actions > start a program: powershell.exe -executionpolicy ByPass -file “D:shutdown computer.ps1” -WindowStyle hidden

    Code:
    Start-Process -WindowStyle hidden -FilePath ‘SHUTDOWN.exe’ -ArgumentList ‘/A’

    # Display Pop-Up Window – [URL=”https://msdn.microsoft.com/en-us/library/x83z1d9f(v=vs.84).aspx”]https://msdn.microsoft.com/en-us/lib…(v=vs.84).aspx[/URL]
    $wshell = New-Object -ComObject Wscript.Shell
    $confirmation = $wshell.Popup(“Your computer is scheduled to shutdown within 10 min.nnClick Cancel to abort the shutdown”,600,”Attention…”, 0x1 + 0x40 + 0x1000)

    if ($confirmation -eq -1) {
    Start-Process -WindowStyle hidden -FilePath ‘SHUTDOWN.exe’ -ArgumentList ‘/S’,’/F’,’/T 10′
    }
    if ($confirmation -ne 2) {
    Start-Process -WindowStyle hidden -FilePath ‘SHUTDOWN.exe’ -ArgumentList ‘/S’,’/F’,’/T 600′
    }

    Avatar
    Rems
    Moderator
    in reply to: wscript launch exe file spaces in path #228474
    confuseis;n509089 wrote:
    The space in the Recorded TV section of the file name is the blocker here.

    Error: There is no file extension with “c:usersrecorded”,

    The articles Ive read mention using triple quotes “””

    Have you tried with doubled double quotes around the paths?, …not tripled.

    Because the “wscript.exe … ” command line is put between double quotes (the whole is one parameter on the owexec.exe command line) the inner double quotes needs to be escaped in order to prevent the owexec.exe command line will break, or the wscript.exe command line will fail.

    [B]”wscript.exe “”C:UsersPublicRecorded TVJK3.vbs”” “”C:UsersPublicRecorded TVTest-wscript.bat”””[/B][/CODE]

    Or you can also try using the escape character (when a CMD prompt is used to execute the command)

    [CODE] [B]”wscript.exe “C:UsersPublicRecorded TVJK3.vbs” “C:UsersPublicRecorded TVTest-wscript.bat””[/B][/CODE]

    btw The PowerShell escape character is the grave-accent(), Doubled double quotes can be escaped like
    [B]”wscript.exe
    ”C:UsersPublicRecorded TVJK3.vbs”C:UsersPublicRecorded TVTest-wscript.bat””[/B][CODE] “wscript.exe “”C:UsersPublicRecorded TVJK3.vbs”” “”C:UsersPublicRecorded TVTest-wscript.bat”””[/CODE]

    Or you can also try using the escape character (when a CMD prompt is used to execute the command)

    [B]”wscript.exe “C:UsersPublicRecorded TVJK3.vbs” “C:UsersPublicRecorded TVTest-wscript.bat””[/B][/CODE]

    btw The PowerShell escape character is the grave-accent(), Doubled double quotes can be escaped like
    [B]”wscript.exe ”C:UsersPublicRecorded TVJK3.vbs”C:UsersPublicRecorded TVTest-wscript.bat””[/B][CODE] “wscript.exe “C:UsersPublicRecorded TVJK3.vbs” “C:UsersPublicRecorded TVTest-wscript.bat””[/CODE]

    btw The PowerShell escape character is the grave-accent(), Doubled double quotes can be escaped like
    “wscript.exe
    ”C:UsersPublicRecorded TVJK3.vbs”C:UsersPublicRecorded TVTest-wscript.bat`””

    Avatar
    Rems
    Moderator
    in reply to: last password change #228473

    Change -filter * to something as -filter {SAMAccountName -eq “Account Name“}
    or,
    Change -filter * to -identity “Account Name

    http://windowsitpro.com/systems-management/find-users-get-aduser

    Avatar
    Rems
    Moderator

    Internet Explorer will look for a policy in the following order:
    • HKEY_LOCAL_MACHINE policy hive
    • HKEY_CURRENT_USER policy hive
    • HKEY_CURRENT_USER preference hive
    • HKEY_LOCAL_MACHINE preference hive
    It stops on the first hit and does not continue looking.

    Check also whether “Security_HKLM_only” DWORD value is present and has a value of 1, under
    HKEY_LOCAL_MACHINESoftwarePoliciesMicrosoftWin dowsCurrentVersionInternet Settings

    For the ‘Check for signature on downloaded programs’,

    User preference settings are stored here,
    HKEY_CURRENT_USER
    SoftwareMicrosoftInternet ExplorerDownload >> CheckExeSignatures

    Machine GPO settings are stored here,
    HKEY_LOCAL_MACHINE
    ​ SoftwarePoliciesMicrosoftInternet ExplorerDownload Criteria >> CheckExeSignatures

    Avatar
    Rems
    Moderator
    in reply to: net use famous 53 error #228471

    Just remove the backslash at the end op the path.

    net.exe use X: “\jr17v00001.domain.localdhcpbackup” /p:n

    Avatar
    Rems
    Moderator
    in reply to: Powershell passing info to cmd line #228470

    Maybe something like,

    Code:
    Invoke-Command -ComputerName . -ScriptBlock {(Dism.exe /Online /Get-Packages | findstr /i “KB2952664”) -replace “Package Identity : “, “” | % {Dism.exe /Online /Remove-Package /PackageName:$_}}
    Avatar
    Rems
    Moderator
    in reply to: Display accounts expiration dates from list of users #228469

    Here a sample,

    $Today = [datetime]::Today
    $MaxPasswordAge = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge.TotalDays

    [email protected](
    @{n=”AccName”;e={$_.sAMAccountName}}
    @{n=”AccExpDate”;e={$_.AccountExpirationDate}}
    @{n=”AccIsExpired”;e={$($_.AccountExpirationDate -ne $null) -and ($_.AccountExpirationDate -le $Today)}}
    @{n=”AccIsDisabled”;e={$($_.Enabled -eq $false)}}
    @{n=”AccIsLockedOut”;e={$_.LockedOut}}
    @{n=”PwIsExpired”;e={$($_.PasswordLastSet.AddDays($MaxPasswordAge) -le $Today)}}
    )

    Get-Content “c:USERS.txt” | Get-ADUser -properties AccountExpirationDate,LockedOut,PasswordLastSet | Select-Object $props | Export-Csv “C:exportusers.csv” -notypeinfo
    [/CODE][CODE]$Today = [datetime]::Today
    $MaxPasswordAge = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge.TotalDays

    [email protected](
    @{n=”AccName”;e={$_.sAMAccountName}}
    @{n=”AccExpDate”;e={$_.AccountExpirationDate}}
    @{n=”AccIsExpired”;e={$($_.AccountExpirationDate -ne $null) -and ($_.AccountExpirationDate -le $Today)}}
    @{n=”AccIsDisabled”;e={$($_.Enabled -eq $false)}}
    @{n=”AccIsLockedOut”;e={$_.LockedOut}}
    @{n=”PwIsExpired”;e={$($_.PasswordLastSet.AddDays($MaxPasswordAge) -le $Today)}}
    )

    Get-Content “c:USERS.txt” | Get-ADUser -properties AccountExpirationDate,LockedOut,PasswordLastSet | Select-Object $props | Export-Csv “C:exportusers.csv” -notypeinfo
    [/CODE]

    Avatar
    Rems
    Moderator
    Code:
    $search = “ou=MyOU2,OU=MyOU1,dc=mydomain,dc=com”

    [email protected](
    “Name”
    “GivenName”
    “Surname”
    “EmployeeType”
    @{n=”ObjectClass”;e={(Get-Culture).TextInfo.ToTitleCase($_.ObjectClass)}}
    “UserPrincipalName”
    “Enabled”
    “DistinguishedName”
    “SamAccountName”
    @{n=”ManagerName”;e={(Get-ADUser -Identity $_.Manager -properties Name).Name}}
    “Description”
    “Location”
    “City”
    “Office”
    “Country”
    “c”
    @{n=”Region”;e={$_.co}}
    “countryCode”
    “LastLogonDate”
    @{n=”ExpiryDate”;e={[datetime]::FromFileTime($_.”msDS-UserPasswordExpiryTimeComputed”)}}
    “LockedOut”
    “pass*”
    )

    Get-ADUser -filter * -Properties *,”msDS-UserPasswordExpiryTimeComputed” -SearchBase $search | Select-Object $props | Export-Csv “GetUsersByProperty_Output.csv” -notypeinfo -encoding “UTF8”

    Avatar
    Rems
    Moderator
    atulram;n494088 wrote:
    [noparse]@Rems[/noparse] can we also arrange [FONT=&quot]memberOf column value[/FONT] so there is one row per user/group combination?

    That is possible. See the Explanation here, http://blogs.technet.com/b/evand/arc…-together.aspx

    For your question, these are the three steps…

    1. Get-ADUsers load the desired attributes of each into a Hash Table. Create an Array of the collection of the groups of all these users. Remove duplicate groups from the array.
    2. Get-ADGroupMember of each of the groups in the Array, filter the users from $search. Next, using the userobject’s distinguishedName to link the member with the user from Hash Table.
    3. Export UserDetails to CSV file.
    Code:
    [URL=”https://www.petri.com/forums/filedata/fetch?id=494262&d=1446925196″]63668-powershell, include password attributes.txt[/URL]

    If you have specific intrested in Security groups (User access rights and permissions) then you likely also intrested in groups the user is indirectly memberof. If that is the case then replace the line:
    $Groups += $_.MemberOf | Get-ADGroup | %{$_.sAMAccountName}
    With:
    $Groups += Get-ADPrincipalGroupMembership $_.distinguishedName | %{$_.sAMAccountName}

    Avatar
    Rems
    Moderator

    atulram;n494068 wrote:
    hello everyone..good post.
    The memberOf attribute returns DN names, I want simple group names for below script:

    [noparse][script…][/noparse]

    can anyone please assist me.
    Thanks

    Import-Module ActiveDirectory

    $search=’dc=xyz,dc=abc’

    [email protected](
    ‘Name’,
    ‘sAMAccountName’,
    ‘Description’,
    ‘Enabled’,
    ‘created’,
    ‘modified’,
    @{n=”MemberOf”;e={($_.memberof | %{(Get-ADGroup $_).sAMAccountName}) -join “;”}},
    ‘LastLogonDate’,
    ‘LockedOut’
    )

    Get-ADUser -filter * -Properties * -SearchBase $search | select $props | export-Csv “C:new.csv” -notypeinfo -encoding “UTF8”

    [/Code][Code]
    Import-Module ActiveDirectory

    $search=’dc=xyz,dc=abc’

    [email protected](
    ‘Name’,
    ‘sAMAccountName’,
    ‘Description’,
    ‘Enabled’,
    ‘created’,
    ‘modified’,
    @{n=”MemberOf”;e={($_.memberof | %{(Get-ADGroup $_).sAMAccountName}) -join “;”}},
    ‘LastLogonDate’,
    ‘LockedOut’
    )

    Get-ADUser -filter * -Properties * -SearchBase $search | select $props | export-Csv “C:new.csv” -notypeinfo -encoding “UTF8”

    [/Code]

    Avatar
    Rems
    Moderator
    in reply to: Multiple Command Prompt with Ping request with a single script #228465

    Hello Handam,

    Here is an example.
    Three network-ids of 3 octets have been defined in this batch. For the last octet a range from 1 to 255 is used to construct IPv4 addresses.

    Code:
    @goto:begin of batch

    :pinging subroutine
    For %%n in (%NetID%) do For /L %%h in (1,1,255) do PING.exe -n 1 %%n.%%h | find /i “ttl=”
    exit /b 0

    :begin of batch
    [USER=”68995″]Echo[/USER] off
    Set “NetID=[B]192.168.1[/B], [B]192.168.2[/B], [B]192.168.3[/B], [B]192.168.4[/B]”
    > “pingresult.txt” call:pinging

    Avatar
    Rems
    Moderator

    The code contains everytime the same typo…

    It is in the line:
    If ($hasDest.LastWriteTime -gt $hashSrc.LastWriteTime)

    where $hasDest.LastWriteTime should be $hashDest.LastWriteTime

    Avatar
    Rems
    Moderator
    in reply to: Script to remove old files #228463

    Will this do what you want to accomplish?

    Code:
    $limit = (Get-Date).AddDays(-60)
    Get-ChildItem ‘D:folder’ -recurse | Where-Object {!$_.PSIsContainer -and $_.CreationTime -lt $limit -and $_.BaseName -notMatch “.*YTD$” } | Remove-Item -force [B]-whatif[/B]
    Avatar
    Rems
    Moderator
    in reply to: Citrix reciever on a terminal server #228462

    Do the users use a different internet browser? Do they use the most recent version of Citrix Receiver?

    Make sure the login domain is added to Trusted sides. If a user uses the Chrome browser check is the citrix browser-plug-in is not blocked by chrome.

    Avatar
    Rems
    Moderator
    in reply to: vbs script and RunAs command #228461
    balubeto;n490319 wrote:
    By case, I should enable the hidden Administrator account?

    Why? the admin account launching the script does not necessarily have to be thé built-in Administrator account. You can use any account that is a member of the local group Administrators.

    The account you use for this should of course be an enabled account and the password should not be expired. For the Runas service it is required that this admin account do has a password.
    The account may or not necessary needs elevation to launch the script.

    If you intend to run this script using the built-in administrator account (or the system account) then you better uncomment the line:
    REM if bElevate Or WScript.Arguments.Count = 0 Then ElevateUAC

    Avatar
    Rems
    Moderator
    in reply to: comment out #228460
    mla;n490294 wrote:
    I got a config file with all the entry lines starting with ;
    […]
    in suppliers doc they say it should be enabled.
    Am I wrong?

    EDIT: found couple of entries without “;” . So “panic” canceled.

    Should be it -comment out. Just waiting for confirmation if after 9 views no answer so people not sure… But I believe it is clearly comment out.

    REM can be used to comment out a line in some scripting languages. Your file is not a script file, therefore you mostlikely cannot use Rem to comment out a line in the file.

    The part of the content that you showed is typically for INI files or, like you said a configuration file. Yes commonly you can comment out lines in an INI file by inserting a semicolon at the beginning of the line.

    I cannot help you with the question if you should uncomment certain lines. It depense, but… I have not installed your systems, we cannot know where it is for and how it does affect running processes.
    Commented lines in a pre-configured INI file could be there for several reasons. They could be added just as example. Or, lines could be commented out because you have to adjust values to your environment first before you should uncomment. It could be optional does not always have to be required.
    Settings elsewhere (i.e. in the registry, xml files, ect) can sometimes take precedence over values in an INI file. This is very often the case.

    If you are happy how it works for the last years why bother making changes to the config file now? If you try to solve an issue read the manual of the product to learn what needed to be adjusted in the config file. I would not start making changes to an INI file first just to see what will happen afterwards in a good way or bad.

    Avatar
    Rems
    Moderator
    in reply to: vbs script and RunAs command #228459
    balubeto;n490311 wrote:
    Hi

    In Windows 7 SP1 64 bit, as I should do to run a .vbs script with elevated privileges with RunAs command?

    Thanks

    Bye

    ) Do you manually start the script? Then you can try the sample script you showed in your second post (just double click on the vbs file, it re-launces itself elevated). But you still have be logged in to Windows with an admin account to be able to uninstall most applications.

    Alternatively, you could add “Run as admin” to the ‘right click menu’ for vbs files on each computer.

    ) If the script is auto launched by a GPO, then make it run as computer Start-up Script. The script will then be executed by the ‘System account’ (Neither the System account nor the built-in Administrator account are subject to UAC).

    Avatar
    Rems
    Moderator
    in reply to: Need help adding a progess bar to code #228458

    Hi Shazam

    You can try this script,

    Code:
    Const FOF_CREATEPROGRESSDLG = &H510&

    Dim objShell, sFolderToCopy
    Set objShell = CreateObject(“Shell.Application”)

    sFolderToCopy = “C:Test”

    Set dUSBKeys = ScanForUSBKeys()
    For Each oUSBKey in dUSBKeys.Keys
    sKey = oUSBKey
    If not Right(oUSBKey, 1) = “” Then sKey = oUSBKey & “”

    CopyTo sKey

    Next

    Sub CopyTo(Destination)
    Set oDestFldr = objShell.NameSpace(Destination)
    oDestFldr.CopyHere sFolderToCopy, FOF_CREATEPROGRESSDLG
    End Sub

    Function ScanForUSBKeys()
    Set oWMI = GetObject(“winmgmts:\.rootcimv2”)
    Set dTemp = CreateObject(“Scripting.Dictionary”)

    Set cDisks = oWMI.ExecQuery(“Select InterfaceType,MediaType,PNPDeviceID,DeviceID,Size from Win32_DiskDrive”)
    For Each oDisk in cDisks
    If InStr(LCase(oDisk.InterfaceType),”usb”) > 0 AND InStr(LCase(oDisk.MediaType),”removable”) > 0 _
    AND InStr(LCase(oDisk.PNPDeviceID),”blackberry”) = 0 AND InStr(LCase(oDisk.PNPDeviceID),”ipod”) = 0 _
    AND NOT oDisk.PNPDeviceID = “” Then
    Set cDrivePartitions = oWMI.ExecQuery(“ASSOCIATORS OF {Win32_DiskDrive.DeviceID='” & _
    oDisk.DeviceID & “‘} WHERE AssocClass = Win32_DiskDriveToDiskPartition” )
    For Each oDrivePartition in cDrivePartitions
    Set cDriveLetters = oWMI.ExecQuery(“ASSOCIATORS OF {Win32_DiskPartition.DeviceID='” & _
    oDrivePartition.DeviceID & “‘} WHERE AssocClass = Win32_LogicalDiskToPartition”)
    For Each oDriveLetter in cDriveLetters
    dTemp.Add oDriveLetter.DeviceID, 1
    Next
    Set cDriveLetters = Nothing
    Next
    Set cDrivePartitions = Nothing
    End If
    Next
    Set cDisks = Nothing
    Set ScanForUSBKeys = dTemp
    Set dTemp = Nothing
    Set oWMI = Nothing
    End Function

    Avatar
    Rems
    Moderator
    in reply to: reg key #228457

    Re: reg key

    mla;290344 wrote:
    I need to accomplish a task that requires registry value add by GPO.

    on the pic I have a recommended script.

    I would like to manually create the required registry on a test pc.

    The entries being added to the registry by the .reg file that is showed on the image are:
    create a new Key “AllowedDomains” under iexplore
    create a sub Key “msn.com” under “AllowedDomains”
    create a sub Key “microsoft.com” under “AllowedDomains”

    Avatar
    Rems
    Moderator
    in reply to: Need Help to Modify Pinning Shortcut VBScript #228456

    Re: Need Help to Modify Pinning Shortcut VBScript

    Shazam;290103 wrote:
    So I change one thing in your code to act as a wildcard. using “*” .I ran the VBSafter adding the asterisk and it ran just fine, but is that the proper way of doing it?

    [COLOR=DarkOrange]AppPath = “C:Program Files (x86)AdobeReader*ReaderAcroRd32.exe”[/COLOR][/CODE][/QUOTE]

    Wildcards in the string is not supported. With the * the file path has become unvalid.

    The AppPath variable is actually defined for a second time by the [COLOR=”DarkOrange”]second orange line[/COLOR] is where it retrieves the program path of AcroRd32.exe from registry.

    Basically the the first orange line is in most cases fully redundant.

    /Rems[CODE]AppPath = “C:Program Files (x86)AdobeReader*ReaderAcroRd32.exe”[/CODE]

    Wildcards in the string is not supported. With the * the file path has become unvalid.

    The AppPath variable is actually defined for a second time by the second orange line is where it retrieves the program path of AcroRd32.exe from registry.

    Basically the the first orange line is in most cases fully redundant.

    /Rems

    Avatar
    Rems
    Moderator
    in reply to: Need Help to Modify Pinning Shortcut VBScript #228455

    Re: Need Help to Modify Pinning Shortcut VBScript

    See the part in Orange from the example below. You can adjust this part as you want.

    • The first orange line is where the path to the executable is hard coded (the path you provided).
    • The second line is where it retrieves the actual program path of AcroRd32.exe from registry, in cases were the OS is 32-bit instead of 64 or when a new or older version of the reader was installed.
    • The third checks if AcroRd32.exe really exists at the provided/retrieved program path. If not exist then the user’s default program voor opening PDFs will be used instead of AcroRd32.exe.

    Set WshShell = CreateObject(“WScript.Shell”)
    Set objShell = CreateObject(“Shell.Application”)
    Set objFSO = CreateObject(“Scripting.FileSystemObject”)

    strTartgetFile = “\filesDATAHRPhone ListPhoneListPHONELST.pdf”

    ShortcutName = “PHONELST”
    ShortcutFolder = WshShell.SpecialFolders.Item(“Desktop”)
    ShortcutFile = ShortcutName & “.lnk”

    On Error Resume Next[COLOR=”DarkOrange”]
    AppPath = “C:Program Files (x86)AdobeReader 11.0ReaderAcroRd32.exe”
    AppPath = WshShell.Regread(“HKLMSOFTWAREMicrosoftWindowsCurrentVersionApp PathsAcroRd32.exe”)
    If (objFSO.FileExists(AppPath)=False) Then AppPath = GetProgramAssocWith(“PDF”)
    [/COLOR]On Error Goto 0

    call PinToTaskbar(“unpin”)

    FilePath = ShortcutFolder & “” & ShortcutFile

    With WshShell.CreateShortcut(FilePath)
    .TargetPath = AppPath
    .Arguments = “””” & strTartgetFile & “”””
    .WorkingDirectory = “.”
    .IconLocation = “imageres.dll, 124”
    .Description = “…”
    .Save
    End With

    call PinToTaskbar(“pin”) : WScript.Sleep 950

    objFSO.DeleteFile(FilePath), true

    wscript.quit

    Function GetProgramAssocWith(strExt)
    Const HKCR=&H80000000
    Const HKCU=&H80000001
    Set objReg = GetObject(“winmgmts:\.rootdefault:StdRegProv”)

    strExt = Replace(strExt,”*”,””)
    If Left(strExt,1) “.” Then strExt = “.” & strExt

    strPath = “SoftwareMicrosoftWindowsCurrentVersionExplorerFileExts” & strExt & “UserChoice”
    objReg.GetExpandedStringValue HKCU, strPath, “Progid”, strValue
    If IsNull(strValue) Then
    objReg.GetExpandedStringValue HKCR, strExt, strEntry, strValue
    End If
    If IsNull(strValue) Then wscript.quit

    strPath = strValue & “shellopencommand”
    objReg.GetExpandedStringValue HKCR, strPath, strEntry, strValue
    strValue = Replace(strValue, “”””, “”)

    http://www.akaplan.com/blog/2010/12/…ile-extension/
    If InStr(strValue,”rundll”) Then
    Dim tArray
    tArray = split(strValue,”,”)
    GetProgramAssocWith = replace(tArray(0),”rundll32.exe”,””)
    Else
    strValue = LCase(strValue)
    GetProgramAssocWith = Left(strValue,instrrev(strValue,”.exe”)+3)
    End If
    End Function

    Sub PinToTaskbar(choice)

    On Error Resume Next

    If Lcase(choice) = “unpin” then

    LnkFolder = WshShell.SpecialFolders.Item(“AppData”)
    LnkFolder = LnkFolder & “MicrosoftInternet ExplorerQuick LaunchUser PinnedTaskBar”
    LnkFile = ShortcutName & “.lnk”

    Set objFolder = objShell.Namespace(LnkFolder)
    Set objFolderItem = objFolder.ParseName(LnkFile)
    Set colVerbs = objFolderItem.Verbs
    For Each objVerb in colVerbs
    Select Case Replace(objVerb.name, “&”, “”)
    case “Unpin from Taskbar” objVerb.DoIt
    case “other language …” objVerb.DoIt
    case “other language …” objVerb.DoIt
    case “other language …” objVerb.DoIt
    End Select
    Next

    ElseIf Lcase(choice) = “pin” then

    Set objFolder = objShell.Namespace(ShortcutFolder)
    Set objFolderItem = objFolder.ParseName(ShortcutFile)
    Set colVerbs = objFolderItem.Verbs
    For Each objVerb in colVerbs
    Select Case Replace(objVerb.name, “&”, “”)
    case “Pin to Taskbar” objVerb.DoIt
    case “Ajouter au menu Démarrer” objVerb.DoIt
    case “Aggiungi a menu Start” objVerb.DoIt
    case “An Startmenü anheften” objVerb.DoIt
    case “Aan het menu Start vastmaken” objVerb.DoIt
    case “Associar ao Menu Iniciar” objVerb.DoIt
    case “Anclar al menú Inicio” objVerb.DoIt
    End Select
    Next

    End If
    End Sub
    [/CODE][CODE]Set WshShell = CreateObject(“WScript.Shell”)
    Set objShell = CreateObject(“Shell.Application”)
    Set objFSO = CreateObject(“Scripting.FileSystemObject”)

    strTartgetFile = “\filesDATAHRPhone ListPhoneListPHONELST.pdf”

    ShortcutName = “PHONELST”
    ShortcutFolder = WshShell.SpecialFolders.Item(“Desktop”)
    ShortcutFile = ShortcutName & “.lnk”

    On Error Resume Next
    AppPath = “C:Program Files (x86)AdobeReader 11.0ReaderAcroRd32.exe”
    AppPath = WshShell.Regread(“HKLMSOFTWAREMicrosoftWindowsCurrentVersionApp PathsAcroRd32.exe”)
    If (objFSO.FileExists(AppPath)=False) Then AppPath = GetProgramAssocWith(“PDF”)
    On Error Goto 0

    call PinToTaskbar(“unpin”)

    FilePath = ShortcutFolder & “” & ShortcutFile

    With WshShell.CreateShortcut(FilePath)
    .TargetPath = AppPath
    .Arguments = “””” & strTartgetFile & “”””
    .WorkingDirectory = “.”
    .IconLocation = “imageres.dll, 124”
    .Description = “…”
    .Save
    End With

    call PinToTaskbar(“pin”) : WScript.Sleep 950

    objFSO.DeleteFile(FilePath), true

    wscript.quit

    Function GetProgramAssocWith(strExt)
    Const HKCR=&H80000000
    Const HKCU=&H80000001
    Set objReg = GetObject(“winmgmts:\.rootdefault:StdRegProv”)

    strExt = Replace(strExt,”*”,””)
    If Left(strExt,1) “.” Then strExt = “.” & strExt

    strPath = “SoftwareMicrosoftWindowsCurrentVersionExplorerFileExts” & strExt & “UserChoice”
    objReg.GetExpandedStringValue HKCU, strPath, “Progid”, strValue
    If IsNull(strValue) Then
    objReg.GetExpandedStringValue HKCR, strExt, strEntry, strValue
    End If
    If IsNull(strValue) Then wscript.quit

    strPath = strValue & “shellopencommand”
    objReg.GetExpandedStringValue HKCR, strPath, strEntry, strValue
    strValue = Replace(strValue, “”””, “”)

    http://www.akaplan.com/blog/2010/12/…ile-extension/
    If InStr(strValue,”rundll”) Then
    Dim tArray
    tArray = split(strValue,”,”)
    GetProgramAssocWith = replace(tArray(0),”rundll32.exe”,””)
    Else
    strValue = LCase(strValue)
    GetProgramAssocWith = Left(strValue,instrrev(strValue,”.exe”)+3)
    End If
    End Function

    Sub PinToTaskbar(choice)

    On Error Resume Next

    If Lcase(choice) = “unpin” then

    LnkFolder = WshShell.SpecialFolders.Item(“AppData”)
    LnkFolder = LnkFolder & “MicrosoftInternet ExplorerQuick LaunchUser PinnedTaskBar”
    LnkFile = ShortcutName & “.lnk”

    Set objFolder = objShell.Namespace(LnkFolder)
    Set objFolderItem = objFolder.ParseName(LnkFile)
    Set colVerbs = objFolderItem.Verbs
    For Each objVerb in colVerbs
    Select Case Replace(objVerb.name, “&”, “”)
    case “Unpin from Taskbar” objVerb.DoIt
    case “other language …” objVerb.DoIt
    case “other language …” objVerb.DoIt
    case “other language …” objVerb.DoIt
    End Select
    Next

    ElseIf Lcase(choice) = “pin” then

    Set objFolder = objShell.Namespace(ShortcutFolder)
    Set objFolderItem = objFolder.ParseName(ShortcutFile)
    Set colVerbs = objFolderItem.Verbs
    For Each objVerb in colVerbs
    Select Case Replace(objVerb.name, “&”, “”)
    case “Pin to Taskbar” objVerb.DoIt
    case “Ajouter au menu Démarrer” objVerb.DoIt
    case “Aggiungi a menu Start” objVerb.DoIt
    case “An Startmenü anheften” objVerb.DoIt
    case “Aan het menu Start vastmaken” objVerb.DoIt
    case “Associar ao Menu Iniciar” objVerb.DoIt
    case “Anclar al menú Inicio” objVerb.DoIt
    End Select
    Next

    End If
    End Sub
    [/CODE]

    Avatar
    Rems
    Moderator
    in reply to: UAC interferes with script need suppress #228454

    Re: UAC interferes with script need suppress

    What is the problem exactly that is caused by UAC? Can you show that part of the script.

    Is this script running as user-logon script or, computer-startup script?, can it run at startup?

    /Rems

    Avatar
    Rems
    Moderator
    in reply to: Quick Reply #228453

    Re: Quick Reply

    The font color picker is showing colors again in new posts.

    Avatar
    Rems
    Moderator
    in reply to: Good ol for do loop #228452

    Re: Good ol for do loop

    Add UseBackQ to the For options, because there are double quotes around the file name.

    “usebackq skip=1”

    /Rems

    Avatar
    Rems
    Moderator
    in reply to: New Moderators / Mod changes? #228451

    Re: New Moderators / Mod changes?

    I am happy to moderate ‘Google Cloud Platform’ and ‘Other Cloud Services’.

    /Remco

Viewing 30 posts - 1 through 30 (of 2,323 total)