logo
down
shadow

Get Current Executable Directory On Map Drive


Get Current Executable Directory On Map Drive

By : Gunjan Tiwari
Date : November 22 2020, 02:59 PM
help you fix your problem I ended up with these 2 functions.
UNC2LocalPath takes UNC Path and return local path. It iterates thru all drives that being map at the local machine. If found a match, it replace server name with the drive letter.
code :
using System.Management;

public static String UNC2LocalPath(String input)
{
    DriveInfo[] dis = DriveInfo.GetDrives();
    foreach (DriveInfo di in dis)
    {
        if (di.DriveType == DriveType.Network)
        {
            DirectoryInfo dir = di.RootDirectory;
            var unc = GetUNCPath(dir.FullName.Substring(0, 2));
            if (input.StartsWith(unc_path, StringComparison.OrdinalIgnoreCase))
            {
                return input.Replace(Path.GetPathRoot(unc) + "\\", dir.FullName);
            }
        }                
    }
    return null;
}

public static string GetUNCPath(string path)
{
    if (path.StartsWith(@"\\"))
        return path;

    ManagementObject mo = new ManagementObject();
    mo.Path = new ManagementPath(string.Format("Win32_LogicalDisk='{0}'", path));

    //DriveType 4 = Network Drive
    if (Convert.ToUInt32(mo["DriveType"]) == 4)
        return Convert.ToString(mo["ProviderName"]);
    else return path;
}


Share : facebook icon twitter icon
osx cannot find an executable in the current directory

osx cannot find an executable in the current directory


By : Einav
Date : March 29 2020, 07:55 AM
hop of those help? I got stuck when chmod a file. , . is not in your path. Use ./myscript.
How do I get compiled python(with cxFreeze) to get the current working directory as the directory where the executable i

How do I get compiled python(with cxFreeze) to get the current working directory as the directory where the executable i


By : user3829059
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further You can use sys.argv. The first element of the command line arguments is always the program itself:
code :
import os
import sys

CWDPATH = os.path.abspath(os.path.dirname(sys.argv[0]))
How can I run any executable file from outside of current directory?

How can I run any executable file from outside of current directory?


By : Saitan
Date : March 29 2020, 07:55 AM
To fix this issue The correct format would be to either start from root, /, or to use the current directory, .. These examples assume that "~$" is your prompt.
Using / from anywhere on your system
C++ - How do you get the current directory of the C++ executable?

C++ - How do you get the current directory of the C++ executable?


By : Ruben Lee Sandoval S
Date : March 29 2020, 07:55 AM
hope this fix your issue Something like this will find you the executable on Windows/Ubuntu/Mac OS X:
code :
#include <vector>

#include <boost/filesystem.hpp>

#if defined(_WIN32)
  #include <windows.h>
#elif defined(__linux__)
  #include <sstream>
  #include <unistd.h>
#elif defined(__APPLE__)
  #include <mach-o/dyld.h>
#endif

boost::filesystem::path find_executable()
{
  unsigned int bufferSize = 512;
  std::vector<char> buffer(bufferSize + 1);

#if defined(_WIN32)
  ::GetModuleFileName(NULL, &buffer[0], bufferSize);

#elif defined(__linux__)
  // Get the process ID.
  int pid = getpid();

  // Construct a path to the symbolic link pointing to the process executable.
  // This is at /proc/<pid>/exe on Linux systems (we hope).
  std::ostringstream oss;
  oss << "/proc/" << pid << "/exe";
  std::string link = oss.str();

  // Read the contents of the link.
  int count = readlink(link.c_str(), &buffer[0], bufferSize);
  if(count == -1) throw std::runtime_error("Could not read symbolic link");
  buffer[count] = '\0';

#elif defined(__APPLE__)
  if(_NSGetExecutablePath(&buffer[0], &bufferSize))
  {
    buffer.resize(bufferSize);
    _NSGetExecutablePath(&buffer[0], &bufferSize);
  }

#else
  #error Cannot yet find the executable on this platform
#endif

  std::string s = &buffer[0];
  return s;
}
Executable is in current directory but can't be run

Executable is in current directory but can't be run


By : oomops
Date : March 29 2020, 07:55 AM
I wish this helpful for you You're trying to run a 32-bit executable on a 64-bit system. Bash doesn't differentiate between this case and "no such file or directory" case.
More about this topic: Executing 32 bit code under Ubundu 64 bit installation error- No such file or directory
Related Posts Related Posts :
  • How to get all ip address in LAN?
  • send value to controller using html.actionlink
  • Assembly "Microsoft.GeneratedCode" loaded
  • count the number of items in view in asp.net mvc
  • Shortcut Keys for Saving or Editing Record in C#
  • Very tricky/complex text formatting: How can I output a string[][] as a table?
  • Fill multiple textboxes after selecting a data from DropDownList in ASP.NET
  • How to launch an application after another is logged in in C#?
  • Unable to retrieve column values from one of the tables joined in a stored procedure?
  • Directories last file name display only
  • Why do I get a COMException when I try to initialize an Interop.Word.Application?
  • Finding subtotal for column in repeater control
  • dropdownlist item selected throw exception (stack empty)
  • How can I list IIS working processes programmatically?
  • How to access nested object from JSON with Json.NET in C#
  • OpenXml DataValidation set predefined List for columns
  • How to find recurring word groups in text with C#?
  • layout conrols to developp universal apps in windows 8.1 pro
  • Adding strings to a list via for loop xna
  • Using Vertex Arrays with OpenTK
  • Optimizing List<string>
  • C# Local variables
  • How can I merge the results of a group by Linq-to-XML query?
  • How to add Report in ASP.NET Project
  • C# How to display all instances of a loop in a label?
  • C# subscribe a function to System.Action that is subscribed to another System.Action: why does order matter?
  • Is there any negative effect to setting SqlCommand's CommandTimeout to a high value?
  • C# - TreeView Context Menu Out of Place when using keyboard
  • How to read stored procedure output and return it as list
  • How do you maintain changes made by VisualState triggers after setting another VisualState?
  • Should I be unit testing my bootstrapper and if so how?
  • using .SingleOrDefault() inside .Where() will raise the following exception:- System.NotSupportedException was unhandled
  • C# How would I fill a Form1 Parameter in the same seperate class
  • Access gridview row's data from LinkButton inside that row
  • Translating excel function to c# Math.pow not resulting in same values
  • Arranging Ten Inputted Numbers into Ascending and Descending order
  • AsEnumerable and Query Syntax
  • How can I defensively code against randomly referencing "Table 0" and null values?
  • Changing xaml code position based on screen size
  • Castle Windsor resolve ienumerable and name
  • Drawing multiple sprites with a for loop xna 4.0
  • For loop to Populate Textblocks
  • Visual Studio 2015: Create an Empty Project
  • What are .NET classes to replace the old MSXML2.ServerXMLHTTP?
  • Handle leak in .Net threads
  • Excel add-in ribbon click events bubbling
  • validation rule needed for only numbers to be entered
  • Parsing complex XML, no descendent elements exists when selecting a named element
  • Web Api - IEnumerable with complex type as param is null
  • Email address input validation
  • .Net AND operator Regular Expression using strings in a document
  • Windows phone 8.1 POST x-www-form-urlencoded not working
  • Is there any way to make my C# XMLManager work?
  • ASP.NET 5 Console Application (package) - How to create DBContext from connection string?
  • How to use form's function in other class C#
  • WPF Zebra EPL2 Printing issue
  • C# use reflection to capture exception throw
  • Convert strings in DataRow to double
  • Xml-Serialization is not working
  • HTML Agility Pack can't find classes with trailing spaces
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co