为IExpress使用exe文件



我正在制作一个安装程序,使用IExpress来解压缩文件,创建一个文件夹并将文件移动到该文件夹。

然而,当选择在安装时运行哪个程序时,我只能使用批处理文件:使其工作

@ECHO OFF
MD C:PlugInFolder

MOVE /Y "%USERPROFILE%AppDataLocalTempIXP000.TMP*.png" C:PlugInFolder
MOVE /Y "%USERPROFILE%AppDataLocalTempIXP000.TMPPlugIn.dll" C:PlugInFolder
MOVE /Y "%USERPROFILE%AppDataLocalTempIXP000.TMPPlugIn2021.addin" C:ProgramDataAutodeskRevitAddins2021
MOVE /Y "%USERPROFILE%AppDataLocalTempIXP000.TMPPlugIn2022.addin" C:ProgramDataAutodeskRevitAddins2022

是否可以运行exe文件?我尝试了以下C#代码(仅用于其中一个文件(,但它只创建文件夹,不移动文件:

// Creating paths
string path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
string folderName = "PlugInFolder";
string pathString = Path.Combine(path, folderName) + "\PlugIn.dll";
string tempName = Path.GetTempPath() + "IXP000.TMP\";
string fileName = "PlugIn.dll";
string filePath = tempName + fileName;
// Creating new directory
Directory.CreateDirectory(pathString);
// Moving files from temp folder
File.Move(filePath, pathString);

您的代码中有一些拼写错误。以下是正确使用Path可以工作的内容。Combine是一个强大的命令:

// Creating paths
string source = Path.Combine(Path.GetTempPath(), "IXP000.TMP");
string dest1 = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
string dest2 = "PlugInFolder";
string dest = Path.Combine(dest1, dest2);
// Creating new directory
// Directory.CreateDirectory(dest);
// Don't create the directory, because we will use Directory.Move
// and it would raise an exception "Directory already exists" 
// Moving files from temp folder to destination
// File.Move is meant to move one file at a time.
// For an entire directory, use Directory.Move which can also be used for renaming the directory.
Directory.Move(source, dest);

顺便问一下,将应用程序放在用户配置文件目录中是一种选择吗?否则,您可以使用:

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

例如在Windows 11中的C:\Users\yourName\AppData\Roaming。

相关内容

  • 没有找到相关文章

最新更新