Wednesday, February 1, 2017

Windows File Sharing

Some bits here are guesses

A machine will not necessarily let another machine see the files on it at all.
Under network and sharing center, go to advanced sharing and let it share with guest or public machines.
I believe this allows other machines to initiate sharing, but some sort of permissions may still prevent sharing - even if sharing for everyone has full control.

On the machine trying to access the files on the remote machine you can have it use credentials to get access.
Go to Credential Manager -> Windows Credentials
Add the remote machine by ip name or ip number.
Add an account and password that has permissions on the remote machine.

For some minimal level of security, make an account on the remote file machine for file sharing.
Only give it access to the shared directory.
Use that accounts credential in Credential Manager.

Monday, January 30, 2017

Install .NET 3.5 on Windows 10

I couldn't get this to work in any of the standard ways.
I mounted my Windows 10 installation media on M:\
I ran this command:

dism /online /enable-feature /FeatureName:NetFx3 /All /LimitAccess /Source:M:\sources\sxs

It worked!

I looked at the Windows Features tree and saw that 3.5 was now there.

Monday, November 28, 2016

c++ Pause Hack

A Snippet to use to make something pause until a debugger can attach to it.

void pauseForTest()
{
FILE *fin = 0;
do {
if (fin)
fclose(fin);
::Sleep(2000);
fin = fopen("C:\\delme\\pause.txt", "r");
} while (fin);
}

Wednesday, October 12, 2016

c++ Diagnostic Logging Hack

Here is a quick and dirty c++ logging hack.
I got tired of recreating something like it.


LoggingHack.h


#ifdef LOGGING_HACK

class JLogStream
{
public:
virtual ~JLogStream() {
}
};

extern JLogStream* jlogs;

extern JLogStream& operator<< (JLogStream& rlog, const std::string& val);
extern JLogStream& operator<< (JLogStream& rlog, const std::wstring& val);
extern JLogStream& operator<< (JLogStream& rlog, const char* zStr);
extern JLogStream& operator<< (JLogStream& rlog, const wchar_t* zStr);
extern JLogStream& operator<< (JLogStream& rlog, int val);
extern JLogStream& operator<< (JLogStream& rlog, std::stringstream &val);
extern JLogStream& operator<< (JLogStream& rlog, std::wstringstream &val);

#define JLOG( x ) { (*jlogs) << x << "\n"; }

#else
#define JLOG( x ) ;
#endif



LoggingHack.cpp




#ifdef LOGGING_HACK

#include <sstream>

#include "LoggingHack.h"

class JLogStreamImpl : public JLogStream
{
private:
FILE* jlog_fout1;
FILE* jlog_fout2;
FILE* jlog_fout3;

public:
JLogStreamImpl()
{
std::stringstream ss1;
ss1 << "c:\\delme\\" << LOGGING_HACK_FILE_BASE_NAME << ".log";
std::stringstream ss2;
ss2 << "c:\\delme\\" << LOGGING_HACK_FILE_BASE_NAME << " - " << ::GetTickCount() << ".log";
std::stringstream ss3;
ss3 << "c:\\delme\\" << LOGGING_HACK_FILE_BASE_NAME << "-rolling.log";

fopen_s(&jlog_fout1, ss1.str().c_str(), "wt");
fopen_s(&jlog_fout2, ss2.str().c_str(), "wt");
fopen_s(&jlog_fout3, ss3.str().c_str(), "at");

log(ss1.str().c_str());
}

void log(const char* zStr)
{
fwrite(zStr, strlen(zStr), 1, jlog_fout1);
fwrite(zStr, strlen(zStr), 1, jlog_fout2);
fwrite(zStr, strlen(zStr), 1, jlog_fout3);

fflush(jlog_fout1);
fflush(jlog_fout2);
fflush(jlog_fout3);
}

void log(const wchar_t* zStr)
{
int ncharLen;
ncharLen = WideCharToMultiByte(CP_UTF8, 0, zStr, -1, NULL, 0, NULL, NULL);
char* zstr = new char[ncharLen];
WideCharToMultiByte(CP_UTF8, 0, zStr, -1, zstr, ncharLen, NULL, NULL);
log("UNICODE:");
log(zstr);
}

void log(int val)
{
std::stringstream ss;
ss << val;
log(ss);
}

void log(std::stringstream &val)
{
log(val.str().c_str());
}

void log(std::wstringstream &val)
{
log(val.str().c_str());
}

};

extern JLogStream& operator<< (JLogStream& rlog, const std::string& val)
{
dynamic_cast<JLogStreamImpl*>(&rlog)->log(val.c_str());
return rlog;
}

extern JLogStream& operator<< (JLogStream& rlog, const std::wstring& val)
{
dynamic_cast<JLogStreamImpl*>(&rlog)->log(val.c_str());
return rlog;
}

extern JLogStream& operator<< (JLogStream& rlog, const char* zStr)
{
dynamic_cast<JLogStreamImpl*>(&rlog)->log(zStr);
return rlog;
}

extern JLogStream& operator<< (JLogStream& rlog, const wchar_t* zStr)
{
dynamic_cast<JLogStreamImpl*>(&rlog)->log(zStr);
return rlog;
}

extern JLogStream& operator<< (JLogStream& rlog, int val)
{
dynamic_cast<JLogStreamImpl*>(&rlog)->log(val);
return rlog;
}

extern JLogStream& operator<< (JLogStream& rlog, std::stringstream &val)
{
dynamic_cast<JLogStreamImpl*>(&rlog)->log(val);
return rlog;
}

extern JLogStream& operator<< (JLogStream& rlog, std::wstringstream &val)
{
dynamic_cast<JLogStreamImpl*>(&rlog)->log(val);
return rlog;
}


JLogStreamImpl theLogStream;

JLogStream* jlogs = &theLogStream;


#else
#define jlog(s) ;
#define jlog(s1, s2) ;
#endif



Include this in one cpp file of the dll or exe: Replacing LogBaseName with the desired name

#define LOGGING_HACK
#define LOGGING_HACK_FILE_BASE_NAME "LogBaseName"
#include "..\..\..\..\LoggingHack.cpp"


Include this in the other cpp files of the module:

#define LOGGING_HACK
#include "..\..\..\..\LoggingHack.h"


Use it like this:

JLOG(__FILE__ << "@" << __LINE__);





Friday, May 27, 2016

Virtualbox crashing VMs on startup

FYI:

*WARNING* Almost *all* of my VM's stopped working today.  I got some error on startup - but before they could really even start to start up.
*In case you have this problem* here is the work around I figured out, it is strange:
1. In virtual box there are some alternate ways to start a VM, one is called "Detachable Start"
2. Start your failing VM using "Detachable Start", you may have to start it twice
3. When it starts is will have crashed Windows and rebooted Windows ( so you will not have the state you saved the VM in )
4. Once it starts, snapshot it and that new snapshot will start up normally.

Friday, May 6, 2016

PostgreSQL database backup and restore

I needed to backup a DB then reset a VM and then put the backup on it.
This is what I did ( I think )

To dump it to a file of sql commands:

pg_dump -U [user-name] [source db name] -f [name of file to dump it to]

One nice thing is that it is human readable.

To reinstall it:

  1. I had to drop the existing DB with the same name ( I used pgAdmin III to do so)
  2. I recreated an empty DB with the same name, and since I needed extensions, I added the 2 extensions I needed.
  3. Then I loaded it in ( which could have been to a different DB name, but in my case I used the same one ):
pgsl -U [user-name] -d [db name to restore to] -f [name of the dump file]

Also note that the commands are found in PostgreSQL's bin directory.