Access Denied When Removing Item

This topic contains 4 replies, has 2 voices, and was last updated by Profile photo of Chris Ediger Chris Ediger 4 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #40183
    Profile photo of Chris Ediger
    Chris Ediger
    Participant

    Writing a little script to uninstall Winvnc. My script is supposed to remove the C:\VNC folder but I keep getting :

    cannot remove item c:\vnc\winvnc.exe: Access to the path 'winvnc.exe' is denied.

    The odd part is that when I step through the lines manually it works with no errors. Is there something different about the way scripts are run vs how they are run manually?

    Here is my script:

    if ((Get-Process).ProcessName -eq "winvnc")
    {
    Stop-Service uvnc_service
    c:\vnc\winvnc.exe -uninstall
    Remove-Item c:\vnc\ -Recurse -Force
    }

    #40188
    Profile photo of Don Jones
    Don Jones
    Keymaster

    It's possible that the uninstaller just isn't getting enough time to complete before moving on to deletion. Try tossing a Start-Sleep in between those two and give it some time to finish.

    #40193
    Profile photo of Chris Ediger
    Chris Ediger
    Participant

    Yep, that did it.
    I had tried putting Start-Sleep after stop-Service.

    Thanks!!

    #40208
    Profile photo of Don Jones
    Don Jones
    Keymaster

    I suspect Stop-Service is running fairly quickly and synchronously. I think the uninstall is what takes time, and it may be running asynchronously. So would Start-Sleep, after the uninstall and before the deletion, be something to try?

    #40213
    Profile photo of Chris Ediger
    Chris Ediger
    Participant

    I realized what you were saying as I submitted that post. I edited it but not in time.

    Yes, that did the trick nicely. I had it pause for 1 second and no error.

    Thanks again!!

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

You must be logged in to reply to this topic.