We have a toolkit written in Perl (ActivePerl, built as 32-bit) and runs on Windows Servers. This toolkit needs to call appcmd.exe at the end of the process, so it always runs as Administrator. All of them work fine, but on one server, the toolkit says it cannot find "C:\Windows\System32\inetsrv\appcmd.exe". But it can be displayed in by the command:
dir C:\Windows\System32\inetsrv\appcmd.exe
In the source code of the toolkit, it detect appcmd.exe like this:
if(-f "C:\\Windows\\System32\\inetsrv\\appcmd.exe"){ #run appcmd.exe command }
Perl is not the only one that cannot find the file. I tried
//This is an example of using stackoverflow.com/a/31043411/34092 // C++17 I tried both 32-bit and 64-bit // 32-bit can find aspnetca.exe, iissetup.exe, w3wp.exe // 64-bit found no .exe file under C:\Windows\System32\inetsrv #include <string> #include <iostream> #include <filesystem> bool ends_with(const std::string& str, const std::string& suffix) { return str.size() >= suffix.size() && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; } int main() { auto path = "C:\\Windows\\System32\\inetsrv"; for (const auto& entry : std::filesystem::directory_iterator(path)) { if (ends_with(entry.path().string(), ".exe")) { std::cout << entry.path() << std::endl; } } }
it doesn't give me appcmd.exe.
File.Exists(@"C:\Windows\System32\inetsrv\appcmd.exe") //C#
also return a false.
Complete code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace TestAppcmd { class Program { static void Main(string[] args) { if (File.Exists(@"C:\Windows\System32\inetsrv\appcmd.exe")) { Console.WriteLine(@"C:\Windows\System32\inetsrv\appcmd.exe exists!"); } else { foreach(var file in Directory.GetFiles(@"C:\Windows\System32\inetsrv")) { if (file.EndsWith(".exe")) { Console.WriteLine($"{file} found"); } } } } } }
I tried File.OpenRead as this article: Why does System.IO.File.Exists(string path) return false? suggested, but still failed (System.IO.FileNotFoundException)
code:
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.IO; namespace TestAppcmd { class Program { static void Main(string[] args) { using (var fr = File.OpenRead(@"C:\Windows\System32\inetsrv\appcmd.exe")) { for (int i = 0; i < (args.Length < 1 ? 250 : int.Parse(args[0])); ++i) { Console.Write((char)fr.ReadByte()); } Console.WriteLine(""); } } } }
Why I can see C:\Windows\System32\inetsrv\appcmd.exe in the folder but unable to access it programmatically?
The answer of System.IO.File.Exists(@"C:\Windows\System32\SnippingTool.exe") returns false doesn't seem to answer my question. Because all of my client's Windows server work fine with my toolkit except one.
Is there any setting that can prevent my toolkit from finding C:\Windows\System32\inetsrv\appcmd.exe.
Please notice that the toolkit works fine on thousands of my clients' server, only one server has such issue. It couldn't be a common feature of Windows. I think probably there is a setting that causes the issue. But I don't know what causes it. The Read/Write/Execute Permission setting on that server is the same as other servers'.
I tried to copy C:\Windows\System32\inetsrv\appcmd.exe to other folder, my toolkit can find it. But if I tried:
:: My current user has full access (Read, Write, Execute, etc.) to %OTHER_FOLDER%\appcmd.exe copy %OTHER_FOLDER%\appcmd.exe C:\Windows\System32\inetsrv\appcmd_new.exe
Or
move C:\Windows\System32\inetsrv\appcmd.exe C:\Windows\System32\inetsrv\appcmd_new.exe
The file appcmd_new.exe becomes invisible to the toolkit.
Then I tried to make a hard link using mklink, it failed because mklink cannot find C:\Windows\System32\inetsrv\appcmd.exe neither
mklinke /H C:\Windows\System32\inetsrv\appcmd.exe .\appcmd.exe
Again the answer stackoverflow.com/a/31043411/34092 doesn't help here.
https://stackoverflow.com/questions/65371785/some-windows-setting-might-block-me-toolkit-from-finding-c-windows-system32-ine December 20, 2020 at 12:07AM
没有评论:
发表评论