Rectangle 27 1

The selected answer will not work if the widget assigns an event listener to the button. And this seems very likely based on the code provided. It will instead display two confirmation dialogs, which is quite confusing.

As a workaround, OP might override the window confirm method. The replacement method could intercept both the message and the result. And while I wouldn't advocate overriding native methods, it is a pragmatic solution that I've used successfully with legacy systems.

var confirm2 = window.confirm;

window.confirm = function(message) {

  var result = confirm2(message);

  debug.innerHTML += 'confirm: ' + message + '\nresult = ' + result + '\n';

  return result;

}


// Simulate 3rd Party Widget
var widget = (function() {

  var methods = {
    confirmDelete: function(event) {
      var go_ahead = confirm("Are you sure you want to delete this draft? This action cannot be undone.");
      if (go_ahead) {
        return;
      } else {
        event.preventDefault();
      }
    }
  }

  document.getElementsByName('delete')[0].addEventListener('click', methods.confirmDelete);

  return methods;

})();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button name="delete">Delete</button>
<xmp id="debug"></xmp>

jquery - Javascript confirm, capturing the user selection - Stack Over...

javascript jquery html
Rectangle 27 1

You are using wrong form name:

document.addStudentForm
document.registerAppointment

You are awesome. Don't know HOW I did not notice that. Long day of coding I guess. :) Thanks!

javascript - why is this JS confirm window not firing on form submit? ...

javascript forms submit confirm
Rectangle 27 35

Maybe bash doesn't see your Windows path. Type env|grep PATH in bash to confirm what path it sees.

Try running "which your_batch_file.bat" (without quotes). It should return the location of your batch file, if it really is in the path.

@AngelS.Moreno update or create a ".bashrc" file under your home directory (e.g. "vim ~/.bashrc" in git bash/cygwin), then add "PATH=$PATH:<your_path_1>:<your_path_2>:...:<your_path_n>" to this file. So, if you wanted "/usr/bin/mypath" to be in the PATH variable, this line would read: PATH=$PATH:/usr/bin/mypath

windows - Git Bash doesn't see my PATH - Stack Overflow

windows bash git-bash
Rectangle 27 2

I also like to confirm that the string isn't a directory:

DWORD attr = GetFileAttributes(file);
if(attr == INVALID_FILE_ATTRIBUTES || (attr & FILE_ATTRIBUTE_DIRECTORY))
    return false;   //  not a file
return true;

Once again that constant is already defined -- FILE_ATTRIBUTE_DIRECTORY.

Updated, thanks - the original code used CFile::directory and a quick search didn't turn up the right substitute.

C++: Which is the best method of checking for file existence on window...

c++ windows file-io
Rectangle 27 5

I`m using the following code to validate credentials. The method shown below will confirm if the credentials are correct and if not wether the password is expired or needs change.

using System;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
using System.Runtime.InteropServices;

namespace User
{
    public static class UserValidation
    {
        [DllImport("advapi32.dll", SetLastError = true)]
        static extern bool LogonUser(string principal, string authority, string password, LogonTypes logonType, LogonProviders logonProvider, out IntPtr token);
        [DllImport("kernel32.dll", SetLastError = true)]
        static extern bool CloseHandle(IntPtr handle);
        enum LogonProviders : uint
        {
            Default = 0, // default for platform (use this!)
            WinNT35,     // sends smoke signals to authority
            WinNT40,     // uses NTLM
            WinNT50      // negotiates Kerb or NTLM
        }
        enum LogonTypes : uint
        {
            Interactive = 2,
            Network = 3,
            Batch = 4,
            Service = 5,
            Unlock = 7,
            NetworkCleartext = 8,
            NewCredentials = 9
        }
        public  const int ERROR_PASSWORD_MUST_CHANGE = 1907;
        public  const int ERROR_LOGON_FAILURE = 1326;
        public  const int ERROR_ACCOUNT_RESTRICTION = 1327;
        public  const int ERROR_ACCOUNT_DISABLED = 1331;
        public  const int ERROR_INVALID_LOGON_HOURS = 1328;
        public  const int ERROR_NO_LOGON_SERVERS = 1311;
        public  const int ERROR_INVALID_WORKSTATION = 1329;
        public  const int ERROR_ACCOUNT_LOCKED_OUT = 1909;      //It gives this error if the account is locked, REGARDLESS OF WHETHER VALID CREDENTIALS WERE PROVIDED!!!
        public  const int ERROR_ACCOUNT_EXPIRED = 1793;
        public  const int ERROR_PASSWORD_EXPIRED = 1330;

        public static int CheckUserLogon(string username, string password, string domain_fqdn)
        {
            int errorCode = 0;
            using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, domain_fqdn, "ADMIN_USER", "PASSWORD"))
            {
                if (!pc.ValidateCredentials(username, password))
                {
                    IntPtr token = new IntPtr();
                    try
                    {
                        if (!LogonUser(username, domain_fqdn, password, LogonTypes.Network, LogonProviders.Default, out token))
                        {
                            errorCode = Marshal.GetLastWin32Error();
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    finally
                    {
                        CloseHandle(token);
                    }
                }
            }
            return errorCode;
        }
    }

this is "method 2" described in the question... so... not really answering the question

c# - How to validate domain credentials? - Stack Overflow

c# windows security authentication
Rectangle 27 5

I`m using the following code to validate credentials. The method shown below will confirm if the credentials are correct and if not wether the password is expired or needs change.

using System;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
using System.Runtime.InteropServices;

namespace User
{
    public static class UserValidation
    {
        [DllImport("advapi32.dll", SetLastError = true)]
        static extern bool LogonUser(string principal, string authority, string password, LogonTypes logonType, LogonProviders logonProvider, out IntPtr token);
        [DllImport("kernel32.dll", SetLastError = true)]
        static extern bool CloseHandle(IntPtr handle);
        enum LogonProviders : uint
        {
            Default = 0, // default for platform (use this!)
            WinNT35,     // sends smoke signals to authority
            WinNT40,     // uses NTLM
            WinNT50      // negotiates Kerb or NTLM
        }
        enum LogonTypes : uint
        {
            Interactive = 2,
            Network = 3,
            Batch = 4,
            Service = 5,
            Unlock = 7,
            NetworkCleartext = 8,
            NewCredentials = 9
        }
        public  const int ERROR_PASSWORD_MUST_CHANGE = 1907;
        public  const int ERROR_LOGON_FAILURE = 1326;
        public  const int ERROR_ACCOUNT_RESTRICTION = 1327;
        public  const int ERROR_ACCOUNT_DISABLED = 1331;
        public  const int ERROR_INVALID_LOGON_HOURS = 1328;
        public  const int ERROR_NO_LOGON_SERVERS = 1311;
        public  const int ERROR_INVALID_WORKSTATION = 1329;
        public  const int ERROR_ACCOUNT_LOCKED_OUT = 1909;      //It gives this error if the account is locked, REGARDLESS OF WHETHER VALID CREDENTIALS WERE PROVIDED!!!
        public  const int ERROR_ACCOUNT_EXPIRED = 1793;
        public  const int ERROR_PASSWORD_EXPIRED = 1330;

        public static int CheckUserLogon(string username, string password, string domain_fqdn)
        {
            int errorCode = 0;
            using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, domain_fqdn, "ADMIN_USER", "PASSWORD"))
            {
                if (!pc.ValidateCredentials(username, password))
                {
                    IntPtr token = new IntPtr();
                    try
                    {
                        if (!LogonUser(username, domain_fqdn, password, LogonTypes.Network, LogonProviders.Default, out token))
                        {
                            errorCode = Marshal.GetLastWin32Error();
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    finally
                    {
                        CloseHandle(token);
                    }
                }
            }
            return errorCode;
        }
    }

this is "method 2" described in the question... so... not really answering the question

c# - How to validate domain credentials? - Stack Overflow

c# windows security authentication
Rectangle 27 28

It seems there's no way to elevate the application privileges for a while for you to perform a particular task. Windows needs to know at the start of the program whether the application requires certain privileges, and will ask the user to confirm when the application performs any tasks that need those privileges. There are two ways to do this:

  • Write a manifest file that tells Windows the application might require some privileges
  • Run the application with elevated privileges from inside another program

What I'd do, if you don't want to write a nasty ctypes wrapper for the CreateElevatedProcess API, is use the ShellExecuteEx trick explained in the Code Project article (Pywin32 comes with a wrapper for ShellExecute). How? Something like this:

When your program starts, it checks if it has Administrator privileges, if it doesn't it runs itself using the ShellExecute trick and exits immediately, if it does, it performs the task at hand.

As you describe your program as a "script", I suppose that's enough for your needs.

Thanks for those links, they were very useful for me finding out a lot about UAC stuff.

Something you might want to note on this is that you can do ShellExecute without PyWin32 (I had problems getting it installed) by using os.startfile($EXECUTABLE, "runas").

@Mike - but runas brings up a new prompt though. And startfile doesn't accept command line arguments to $EXECUTABLE.

I added another answer with a full implementation of this technique that should be able to be added to the start of any python script.

windows - Request UAC elevation from within a Python script? - Stack O...

python windows windows-vista uac
Rectangle 27 28

It seems there's no way to elevate the application privileges for a while for you to perform a particular task. Windows needs to know at the start of the program whether the application requires certain privileges, and will ask the user to confirm when the application performs any tasks that need those privileges. There are two ways to do this:

  • Write a manifest file that tells Windows the application might require some privileges
  • Run the application with elevated privileges from inside another program

What I'd do, if you don't want to write a nasty ctypes wrapper for the CreateElevatedProcess API, is use the ShellExecuteEx trick explained in the Code Project article (Pywin32 comes with a wrapper for ShellExecute). How? Something like this:

When your program starts, it checks if it has Administrator privileges, if it doesn't it runs itself using the ShellExecute trick and exits immediately, if it does, it performs the task at hand.

As you describe your program as a "script", I suppose that's enough for your needs.

Thanks for those links, they were very useful for me finding out a lot about UAC stuff.

Something you might want to note on this is that you can do ShellExecute without PyWin32 (I had problems getting it installed) by using os.startfile($EXECUTABLE, "runas").

@Mike - but runas brings up a new prompt though. And startfile doesn't accept command line arguments to $EXECUTABLE.

I added another answer with a full implementation of this technique that should be able to be added to the start of any python script.

windows - Request UAC elevation from within a Python script? - Stack O...

python windows windows-vista uac
Rectangle 27 28

It seems there's no way to elevate the application privileges for a while for you to perform a particular task. Windows needs to know at the start of the program whether the application requires certain privileges, and will ask the user to confirm when the application performs any tasks that need those privileges. There are two ways to do this:

  • Write a manifest file that tells Windows the application might require some privileges
  • Run the application with elevated privileges from inside another program

What I'd do, if you don't want to write a nasty ctypes wrapper for the CreateElevatedProcess API, is use the ShellExecuteEx trick explained in the Code Project article (Pywin32 comes with a wrapper for ShellExecute). How? Something like this:

When your program starts, it checks if it has Administrator privileges, if it doesn't it runs itself using the ShellExecute trick and exits immediately, if it does, it performs the task at hand.

As you describe your program as a "script", I suppose that's enough for your needs.

Thanks for those links, they were very useful for me finding out a lot about UAC stuff.

Something you might want to note on this is that you can do ShellExecute without PyWin32 (I had problems getting it installed) by using os.startfile($EXECUTABLE, "runas").

@Mike - but runas brings up a new prompt though. And startfile doesn't accept command line arguments to $EXECUTABLE.

I added another answer with a full implementation of this technique that should be able to be added to the start of any python script.

windows - Request UAC elevation from within a Python script? - Stack O...

python windows windows-vista uac
Rectangle 27 5

Seems like the problem is with the user context. Let me confirm whether my assumptions are right.

If both my assumptions are right, please try out the following steps.

Following could be the root cause of your error

This made my day. i was struggling with this problem for 2 days. Finally was able to start the service. Thanks ton!

c# - How do you debug a Windows Service? - Stack Overflow

c# c++ debugging windows-services
Rectangle 27 34

MartinVonMartinsgrn and 4Levels methods confirmed work great on Mac OS X Mountain Lion.

iTerm 2 lets you load global color schemes from a file. Really easy to experiment and try a bunch of color schemes.

Here's a screenshot of the iTerm 2 window and the color preferences.

Once I added the following to my ~/.profile file iTerm 2 was able to override the colors.

export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

Here is a great repository with some nice presets:

Bonus: Choose "Show/hide iTerm2 with a system-wide hotkey" and bind the key with BetterTouchTool for an instant hide/show the terminal with a mouse gesture.

baskerville

@NickWoodhams, what is the color-theme you are using in the screenshot?

@IndradhanushGupta Not sure what color scheme that was, it was a while ago. But now I am using the Pure ZSH theme and loving it. github.com/sindresorhus/pure

this is a nice color scheme and what I needed to check the items types //dirs and etc

osx - OS X Terminal Colors - Stack Overflow

osx shell terminal colors
Rectangle 27 34

MartinVonMartinsgrn and 4Levels methods confirmed work great on Mac OS X Mountain Lion.

iTerm 2 lets you load global color schemes from a file. Really easy to experiment and try a bunch of color schemes.

Here's a screenshot of the iTerm 2 window and the color preferences.

Once I added the following to my ~/.profile file iTerm 2 was able to override the colors.

export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

Here is a great repository with some nice presets:

Bonus: Choose "Show/hide iTerm2 with a system-wide hotkey" and bind the key with BetterTouchTool for an instant hide/show the terminal with a mouse gesture.

baskerville

@NickWoodhams, what is the color-theme you are using in the screenshot?

@IndradhanushGupta Not sure what color scheme that was, it was a while ago. But now I am using the Pure ZSH theme and loving it. github.com/sindresorhus/pure

this is a nice color scheme and what I needed to check the items types //dirs and etc

osx - OS X Terminal Colors - Stack Overflow

osx shell terminal colors
Rectangle 27 3

jQuery(window).on(
    "beforeunload", 
    function() { 
        return confirm("Do you really want to close?") 
    }
)

the onbeforeunload handler should return a string - not a boolean.

jquery - Is there a way to write some javascript functionality when us...

javascript jquery web-applications
Rectangle 27 2

I'm not in front of my win32 dev box, so I can't confirm, but I'll offer two possible approaches:

  • Iterate through the list of processes
  • Call OpenProcess() to get the handle of an existing NETWORK SERVICE process
  • Call OpenProcessToken() using that handle to get the security token from his process
  • Call CreateProcessAsUser() with the token to create a process as NETWORK SERVICE
CreateService()
NT AUTHORITY\NetworkService
lpServiceStartName
StartService()

c++ - CreateProcess running as user: "NT AUTHORITY/Network Service" wi...

c++ windows windows-services
Rectangle 27 6

As ChristopheD noted, I can confirm from practice (ActivePerl on XP) that the shebang line is not really necessary on Windows.

A shebang line tells a Unix shell which interpreter to pass the script to.

On Windows, the program to pass the script to will be determined by associations based on the extension.

On Unix, the third option (full path to perl executable) is best.

And yes, you can use ".." in theory (shell doesn't care) but you should not really use relative path - you never know what your current working directory when executing a script will be.

What should I use for a Perl script's shebang line? - Stack Overflow

perl shebang
Rectangle 27 6

As ChristopheD noted, I can confirm from practice (ActivePerl on XP) that the shebang line is not really necessary on Windows.

A shebang line tells a Unix shell which interpreter to pass the script to.

On Windows, the program to pass the script to will be determined by associations based on the extension.

On Unix, the third option (full path to perl executable) is best.

And yes, you can use ".." in theory (shell doesn't care) but you should not really use relative path - you never know what your current working directory when executing a script will be.

What should I use for a Perl script's shebang line? - Stack Overflow

perl shebang
Rectangle 27 4

Your method '1' actually works. The problem, at least here, is that 'Shell DocObject View' window is not an immediate child of the top-level ie window. Here with IE8, 'Internet Explorer_Server' window is a child of 'Shell DocObject View', which is a child of 'TabWindowClass', which is a child of 'Frame Tab'. If you can confirm 'FindWindowEx' returns 0 in method 1, that's why it fails. The below is the code modified to use EnumChildWindows:

function EnumChilds(hwnd: HWND; lParam: LPARAM): BOOL; stdcall;
const
  Server = 'Internet Explorer_Server';
var
  ClassName: array[0..24] of Char;
begin
  GetClassName(hwnd, ClassName, Length(ClassName));
  Result := ClassName <> Server;
  if not Result then
    PLongWord(lParam)^ := hwnd;
end;

function GetActiveIEServerWindow(const Activate: Boolean=True): HWND;
var
  Wnd, WndChild: HWND;
begin
  Result := 0;
  Wnd := FindWindow('IEFrame', nil); // top level IE
  if Wnd <> 0 then
  begin

//    WndChild := FindWindowEx(Wnd, 0, 'Shell DocObject View', nil);
//    if WndChild <> 0 then
//    begin
//      WndChild := FindWindowEx(WndChild, 0, 'Internet Explorer_Server', nil);

    WndChild := 0;
    EnumChildWindows(Wnd, @EnumChilds, LongWord(@WndChild));

    if WndChild <> 0 then
    begin
      Result := WndChild;
      if Activate then
      begin
        if IsIconic(Wnd) then
          ShowWindow(Wnd, SW_RESTORE)
        else
          SetForegroundWindow(Wnd);
      end;
    end;
//    end;
  end;
end;

As for method '2', I've seen a few links on the web that state IE does not support returning a reference for its active object, but I don't have any official reference for that.

Hi, and thanks for the answer. I'm testing with IE6/XP. so the child window might be different here (It is not the issue). what is your default browser BTW?

But ie6 does not have tabs, $800 makes no sense to ie6. I'm using e8 as mentioned in the answer.

I know, I was hoping IE6 will ignore that (I have also tried to pass 0 as flag), and since I acquire the active IHTMLDocument2 I should be able to Navigate no?.

@kobik - Seems reasonable. I tested the code as I posted in a WM with XPSP2 and Ie6.0.2900.2180(SP2), the existing ie window navigated to the link without launching a new instance, and the flag caused no trouble at all. You're right about the window hieararchy BTW.

Well, I juts realized my IE6 installation is messed up. Thanks for the confirmation, and EnumChildWindows is really the way to go. +1 and accepted.

c# - How to force Internet Explorer to open it's current running insta...

c# c++ delphi internet-explorer winapi
Rectangle 27 6

This is interesting because nView is a 3rd party DLL provided by NVidia. Postings on the internet about nview!NVLoadDatabase suggest that there is an unpatched defect in nview. This is supported by the fact that explorer uses 100% CPU, as confirmed by these reports. See: http://forums.nvidia.com/lofiversion/index.php?t36879.html

As per this article, the hang is due to an infinite loop in nview.dll. Although the assembly instructions and register values described online do not exactly match those in our log, they were close enough for me to conclude that it is the same issue.

To work around the problem, I disabled nView Desktop Manager (Right click on the desktop, select nView Properties, and click disable in the nView Desktop Manager groupbox). Before doing this I was able to consistently reproduce the hang. However, after disabling nView I could not reproduce the hang. Thus, this appears to be a viable workaround.

c++ - Why does my program consume 100% CPU under nVidia NView? - Stack...

c++ windows nvidia
Rectangle 27 3

Thanks for the update. That confirms what the problem is. It was actually described in your original post, but it's quite subtle:

Unfortunately this did not do what you think. It installed the .appx files that can be used to redistribute the framework dependencies. It did not actually install the framework dependencies themselves.

To install them, you have to find the .appx files they installed (or at least the 120 x86 version) and ensure they are also installed. You can do so directly with the App Installer, with Add-AppxPackage separately (and ahead of time), or, I believe, as part of your package's installation by referencing the framework dependency in a -DependencyPath argument.

The path to the .appx file in question looks something like this; tweak the version numbers and platform for your case as required. Just make sure you don't accidentally use a variant without "Desktop" in its name.

Once you install or reference the correct package here, your main package should install (or register) successfully.

Michael, how can I thank you enough for that clear, concise and so so helpful reply ? This solved entirely an issue I had been struggling with for several weeks now. This should be mentioned somewhere on the page about dependencies. I am going to add it there if I can.

I'm glad it helped. As for thanking, stick with the usual. You already accepted the answer; feel free to also upvote it if you think it deserves it. Pay it forward when opportunities come up.

How do I upvote ? I will make sure to share what I received. Actually several Xojo developers are anxious to see me complete submission to the Windows Store and I promised to post a complete step by step how to at forum.xojo.com

windows - Stuck with dependencies in an AppX from Desktop App Converte...

windows desktop appx appxmanifest
Rectangle 27 2

I confirm the author's solution in Windows 10. Using wscript "C:\path\to\foo.vbs" as a shortcut target I can pin my VBS's to the taskbar, and they won't even open a console when running !

windows - Pin a shortcut of a vbs script to the taskbar (W2008 Server)...

windows vbscript