open explorer with path

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 1 year and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
Domtar
Posts: 133
Last visit: Mon Mar 11, 2024 5:38 am
Has voted: 2 times

open explorer with path

Post by Domtar »

hi all,

here's the situation:

I'm writing a GUI to help the service desk in their daily tasks. For that purpose, I need to open an explorer window on a given path on a target computer. If I use invoke-item on the path, the user needs to enter his/her credentials each time they access a new computer, which I'm trying to get rid of.

It looks like this would fix the creds issue:

$creds = get-credential
new-psdrive -psprovider filesystem -name myPSDrive -root \\computer_name\c$\path_needed
invoke explorer here <<<--- not working as needed
remove-psdrive -name myPSDrive

But then, I am unable to open a windows explorer on that given path. Whenever I open explorer, I'm at the default path of it, not the path that I wish to display.

How can I do what I need?

Sorry if this is not clear enough.

Thanks
User avatar
owinsloe
Posts: 161
Last visit: Tue Mar 26, 2024 8:14 pm
Been upvoted: 1 time

Re: open explorer with path

Post by owinsloe »

You don't need all that,
try
&explorer <path>
eg
&explorer c:\temp
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: open explorer with path

Post by jvierra »

Domtar wrote: Fri Sep 16, 2022 6:04 am hi all,

here's the situation:

I'm writing a GUI to help the service desk in their daily tasks. For that purpose, I need to open an explorer window on a given path on a target computer. If I use invoke-item on the path, the user needs to enter his/her credentials each time they access a new computer, which I'm trying to get rid of.

It looks like this would fix the creds issue:

$creds = get-credential
new-psdrive -psprovider filesystem -name myPSDrive -root \\computer_name\c$\path_needed
invoke explorer here <<<--- not working as needed
remove-psdrive -name myPSDrive

But then, I am unable to open a windows explorer on that given path. Whenever I open explorer, I'm at the default path of it, not the path that I wish to display.

How can I do what I need?

Sorry if this is not clear enough.

Thanks
That will happen if you don't have permission on the path or some part of the path.

Why are you creating a "cred" object? Maybe you copied that line by mistake?
User avatar
Domtar
Posts: 133
Last visit: Mon Mar 11, 2024 5:38 am
Has voted: 2 times

Re: open explorer with path

Post by Domtar »

I need the credential object because my GUI is used by the Service Desk to browse files on a targeted computer, to see installation log files and such...

if I use &explorer <path> as suggested by owinsloe, the credential window pops up. since a resource from the service desk can access tens of computers in a day, i'm trying to get rid of them having to enter their creds each time they browse a new computer.

anyway, can someone please suggest a way to do what i need? i need a way to access multiple computers without having to enter my creds for each new pc.

my tool has many options, 2 of them are to be able to open MSI log files & SCCM log files. the user of this tool needs to connect to:

\\computer1\c$\windows\ccmlogs
\\computer2\c$\windows\msilogs

etc...

thanks!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: open explorer with path

Post by jvierra »

This is not a scripting issue. Just add an AD group to all of the folders via Group Policy then add anyone who needs access to the group. Do this once and you have control of who has access by just adding or removing them from the group.
This also eliminates divulging account names and passwords to hackers.
User avatar
Domtar
Posts: 133
Last visit: Mon Mar 11, 2024 5:38 am
Has voted: 2 times

Re: open explorer with path

Post by Domtar »

we already have an AD group that does that. each user is a member of that group. the user name / password is not written anywhere so there is 0 risk for a hacker to get those.

does this mean that you cannot help me resolving my issue?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: open explorer with path

Post by jvierra »

If you have the group, then why do you need to use another account. Just put all users that need access to teh log files in the group.

I think you should start by asking your company security officer and AD people how to get you set up. It is necessary to work with someone who is trained fully in Windows AD networking.

You can also just map a drive to the server, and you will have the access you want.

As far as how to use PowerShell for accessing remote resources here is a free book that will get you up to speed.

https://www.sapien.com/books_training/W ... werShell-4

The command you want is "Get-PsDrive". YOU can get help on any PC command and all syntax elements with the built-in help system which the book shows you how to use.

help Get-PsDrive -full

The help has the examples. Be sure you have completed the PowerShell install and initialization including installing the help documentation. YOU may have security issues if the security on your site has restricted PS security.
User avatar
Domtar
Posts: 133
Last visit: Mon Mar 11, 2024 5:38 am
Has voted: 2 times

Re: open explorer with path

Post by Domtar »

ok, let's take this from scratch.

the GUI is started with the same user that needs to browse the logs. There is no other user account.

if you look at the first post, I did say I'm trying to use new-psdrive & get-psdrive

but when i run get-psdrive with the path i need, it is asking my for credentials. I'm trying to get rid of that credential request.
jvierra wrote: Tue Oct 04, 2022 5:03 am If you have the group, then why do you need to use another account. Just put all users that need access to teh log files in the group.

I think you should start by asking your company security officer and AD people how to get you set up. It is necessary to work with someone who is trained fully in Windows AD networking.

You can also just map a drive to the server, and you will have the access you want.

As far as how to use PowerShell for accessing remote resources here is a free book that will get you up to speed.

https://www.sapien.com/books_training/W ... werShell-4

The command you want is "Get-PsDrive". YOU can get help on any PC command and all syntax elements with the built-in help system which the book shows you how to use.

help Get-PsDrive -full

The help has the examples. Be sure you have completed the PowerShell install and initialization including installing the help documentation. YOU may have security issues if the security on your site has restricted PS security.
User avatar
Domtar
Posts: 133
Last visit: Mon Mar 11, 2024 5:38 am
Has voted: 2 times

Re: open explorer with path

Post by Domtar »

OK i found this and it works.

$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = "\\$($comboPCName.Text)\c$\windows\msi\logs"
$OpenFileDialog.filter = "All files (*.*)| *.*"
$OpenFileDialog.ShowDialog() | Out-Null

thanks!
This topic is 1 year and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked