如何发现用户的桌面文件夹? [英] How do I discover the user's Desktop folder?

查看:23
本文介绍了如何发现用户的桌面文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Visual Studio 中制作一个小应用程序,它在模拟器中加载 ROM.我有两个模拟器和 20 个 ROM.

I'm making a little application in visual studio which loads a ROM in an emulator. I have two emulators and 20 ROMs.

我制作了一个表格并添加了几个按钮.当您单击按钮时,它会打开一个新表单并关闭旧表单.然后在新表单上我有四个按钮:每个按钮在模拟器中加载不同的 ROM.因此,当您按下 Button1 时,会触发此代码:

I made a form and added a few buttons. When you click the Button it opens a new form and closes the old one. Then on the new form I have four buttons: each one loads a different ROM in an emulator. So when you press Button1 this code is triggered:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles yellow.Click
Shell("C:\Users\shifty\Desktop\pokemon games\Emulator\VBA\VisualBoyAdvance.exe ""C:\Users\shifty\Desktop\pokemon games\Roms\Yellow\Pokemon Yellow.gb""", vbNormalFocus)
End Sub

它工作正常 - 我点击它并在模拟器中加载游戏.我遇到的问题是文件路径.如果我将此应用程序发送给朋友,它仍会查找C:\Users\shifty\Desktop\" - 但那是在我的计算机上,而不是他的计算机上.

It works fine - I click it and it loads the game in the emulator. The bit im having trouble with is the file paths. If I send this application to a friend, it would still look for "C:\Users\shifty\Desktop\" - but that's on my computer, not his.

有没有办法让应用程序在他的计算机上查找文件(无需将文件路径更改为 (C:\Users\""他的用户名""\Desktop))

Is there a way to make the application look for the file on his computer (without changing the file path to (C:\Users\""his user name""\Desktop))

推荐答案

Environment.GetFolderPath(Environment.SpecialFolder.Desktop)

这将解析为当前用户的桌面文件夹.

This will resolve to be the desktop folder for the current user.

它甚至可以在 XP、vista 和 Windows 7 之间正常工作.

It will even work between XP, vista and Windows 7 properly.

这篇关于如何发现用户的桌面文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆