Reading file contents does not produce file contents - windows

I have a generic SQL file containing a boring SQL Script. Nothing unusual. However, when I try to read it using VBScript, it produces this output:
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
˜_
And nothing else. Here is my VBScript code that does not work:
Set objFSO = CreateObject("Scripting.FileSystemObject")
WScript.Echo objFSO.OpenTextFile("PARTY_FK_CONSTRAINTS.SQL").ReadAll()
I have tried this in Windows 7 as well as Windows Server 2008 R2. Also worth mentioning is that I can read it just fine in C#. I don't know if something strange is happening transparently through the filesystem or what. What's going on?

Related

How can I solve this VBS code encoding problem? [duplicate]

simply save the following in notepad using UTF-8
msgbox "你好"
double click or run it from command line
D:\>cscript.exe /u test-unicode.vbs
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.
D:\test-unicode.vbs(1, 1) Microsoft VBScript compilation error: Invalid characte
r
is there any way to run the unicode script in Windows Script Host?
cscript.exe can run scripts saved using [Unicode] (seems UTF-16).

Why doesn't pressing the up arrow get the previous command in nested processes

On the command line, I can retrieve previous commands by pressing the up / down arrow keys. This doesn't work however if I nest CMDs beyond a certain depth. Why is that so and is there a way to make it work?
To reproduce, open CMD and run:
Microsoft Windows [Version 10.0.19042.1110]
(c) Microsoft Corporation. All rights reserved.
C:\>cmd
Microsoft Windows [Version 10.0.19042.1110]
(c) Microsoft Corporation. All rights reserved.
C:\>cmd
Microsoft Windows [Version 10.0.19042.1110]
(c) Microsoft Corporation. All rights reserved.
C:\>cmd
Microsoft Windows [Version 10.0.19042.1110]
(c) Microsoft Corporation. All rights reserved.
C:\>cmd
Microsoft Windows [Version 10.0.19042.1110]
(c) Microsoft Corporation. All rights reserved.
C:\>echo lands
lands
C:\>rem Pressing up here doesn't bring back "echo lands"
For more context:
I have a REPL in my Python discord.py bot which uses a subclass of the builtin code module's InteractiveConsole class that supports getting previous lines using the arrow keys (tested it by itself). I use Pew to run my bot in the right virtual environment (with pew in bot python bot.py).
The arrow keys don't work. When I run my bot, Task Manager shows 6 extra processes (processes other than the original cmd.exe and Console Window Host):
pew # Pew's executable on the PATH
python # Pew's virtual environment's Python
python # Global Python
cmd # Pew does subprocess.run(..., shell=True)
python # Bot's virtual environment's Python
python # Global Python
To confirm that it was solely the number of nested processes that mattered, I tried two more things. First, I installed Pew globally (with pip install pew) and ran the bot using python -m pew .... There were 4 extra processes (3 Pythons and 1 CMD) and the arrow keys still didn't work. Then, I made a fork of Pew that doesn't create an intermediate shell and ran the bot using it. There were 3 extra processes (all Pythons) and the arrow keys worked inside the REPL.
I still don't know why this happens, but I've resorted to using ConEmu which doesn't suffer from this issue.

DCompositionCreateDevice2: E_INVALIDARG One or more arguments are invalid

Having an unusual problem running Win32C++ source codes with the function DCompositionCreateDevice2, which is compiled with VS 2015.
The source codes compile without any error but display the above runtime error. Recompiling and running the same source codes with VS 2019, there is no runtime error.
The test sample codes are Windows SDK samples listed below:
TouchInputDirectManipulation
DCompV2BackfaceandD2DBatching
Any idea what could be the source of this problem? I am working on WTL open source project, and do not want to restrict the build environment to VS 2019.
This is actually an unusual issue... What happens is Microsoft has seriously messed up dcomp.lib between the Windows 8.1 SDK and the Windows 10 SDK.
Here is what you see if you dump the Windows 8.1 SDK dcomp.lib exports:
C:\>dumpbin "C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x64\dcomp.lib" /exports
Microsoft (R) COFF/PE Dumper Version 14.28.29914.0
Copyright (C) Microsoft Corporation. All rights reserved.
Exports
ordinal name
DCompositionCreateDevice
1017 DCompositionCreateDevice2
DCompositionCreateSurfaceHandle
And here is what you see if you dump the Windows 10 SDK dcomp.lib exports:
C:\>dumpbin "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x64\dcomp.lib" /exports
Microsoft (R) COFF/PE Dumper Version 14.28.29914.0
Copyright (C) Microsoft Corporation. All rights reserved.
Exports
ordinal name
DCompositionAttachMouseDragToHwnd
DCompositionAttachMouseWheelToHwnd
DCompositionCreateDevice
DCompositionCreateDevice2
DCompositionCreateDevice3
DCompositionCreateSurfaceHandle
As you can see the DCompositionCreateDevice2 was defined with ordinal 1017 initially. When you build your program using the Windows 8.1 SDK (which is how theses samples are currently defined), you get that using dumpbin:
C:\>dumpbin c:\mypath\TouchInputDirectManipulation\cpp\x64\Debug\DirectManipulationSample.exe /imports
Microsoft (R) COFF/PE Dumper Version 14.28.29914.0
Copyright (C) Microsoft Corporation. All rights reserved.
Section contains the following imports:
dcomp.dll
140054570 Import Address Table
140054E98 Import Name Table
0 time date stamp
0 Index of first forwarder reference
Ordinal 1017
So, your .exe is linked to ordinal 1017, not to exported name DCompositionCreateDevice2.
The problem is, with Windows 10 (I think you're running on Windows 10), dcomp ordinal 1017 is not DCompositionCreateDevice2 but DCompositionAttachMouseDragToHwnd! This can be confirmed if you debug your program, you land into that function that doesn't like what you send to it and reports E_INVALIDARG.
So the solution is to change the SDK if you target Windows 10:
Or simply use GetProcAddress("DCompositionCreateDevice2") etc. to dcomp.dll to make sure you get the good one.
This should be reported to Microsoft I guess...

Batch command vcvarsall.bat errors with "input line is too long" on Azure DevOps server

I am running a batch file on Azure DevOps server pipeline as batch script task.
This batch file internally invokes Intel Parallel studio compiler 2019 update 3 like this:
if %ERRORLEVEL% NEQ 0 (
call "%ICPP_COMPILER19%bin\compilervars.bat" intel64 vs2017
)
and later calls build file.
Lately, I am observing this command throws error as:
##[command]C:\build_dir\test.bat
Intel(R) MPI Library 2019 Update 3 for Windows* Target Build Environment for Intel(R) 64 applications
Copyright 2007-2019 Intel Corporation.
Copyright (C) 1985-2019 Intel Corporation. All rights reserved.
Intel(R) Compiler 19.0 Update 3 (package 203)
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.0.26228.57
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
The input line is too long.
The syntax of the command is incorrect.
What is this error and why now? I saw many questions related to this but I couldn't find answers related to my query.
The input line is too long. normally happens after a percent expansion with a resulting line longer than 8191 characters.
In your case it's probably a path/includedir variable overflowing after appending something.
The cause for such problems could be a recursion or multiple invocation of the batch file.
Then you should see that the same path was appended multiple times.
Another problem could be that your project paths are very long, like
C:\my insane Projects\are nested\into a structure\that is much too deep\...<2000 characters later>\myProject
Check your PATH variable, sometimes it's ridiculous long with many repetitions.
To find your problem, add some echo #123 into compilervars.bat to find the exact line.
Then analyse the problematic variable.
My fix was involved resetting the path variable since it got overloaded due to an error in my build script that would run every time I built my project.
Running an echo %PATH% helped me see how long my path variable was.

Powershell issue - 32-bit vs 64-bit

I am having an issue on my machine with PowerShell (x86). If I type:
cmd
I get no output. However, If I type this into 64-bit PowerShell, I get the output:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
And idea why this is behaving this way? It's as if PowerShell (x86) is just not executing this command. I am running 64-bit Windows 7.
Edit: cmd is just an example of what's happening. It also happens when I want to execute foo.exe in some random folder. I'm looking for a solution for the general case of running executables in 32-bit PowerShell.
Edit: In case somebody with the same issue sees this, the way I was able to fix this was by changing my ComSpec environment variable to:
C:\Windows\SysWOW64\cmd.exe
To start and open a 32-bit command prompt you need to type:
$env:windir\SysWoW64\cmd.exe

Resources